Problem in redirection
am 25.08.2007 10:44:50 von Sachin
Hi All
I am trying to use system command to run executable(CLI.exe).
I want output of this executable in a file.So I used redirection
operator.
Here is my code
use Win32;
use Win32::Process;
$CLIPath = "..\\..\\..\\framework\\pc\\tsroot\\mmi\\commandlinetoolset\
\bin\\cli.exe";
###CLIArg contains argumnets to CLI.exe
####There are two statements for CLIArg.The details for taking two
statements are given below:
####Though one is commented
$CLIArg = "-plugin XLauncher -comport COM1 -platform COB15_B02 -
Option NAND -BootScenario Normal";
#$CLIArg = "-plugin FlashAccess -comport AutoConnect -platform
COB15_B02 -OS Symbian";
$CLIArg = $CLIPath." ".$CLIArg;
open STDOUT, '>', "foo.txt";
Win32::Process::Create($CLIObj,
$CLIPath,
$CLIArg,
0,
NORMAL_PRIORITY_CLASS,
".") || die ErrorReport();
$CLIObj->Wait(60000);
$CLIObj->GetExitCode($exitcodeCLI);
if($exitcodeCLI == 259)
{
$Pid = $CLIObj->GetProcessID();
Win32::Process::KillProcess($Pid, $exitcodeCLI);
}
When I use 1st CLIArg statement, CLI.exe remains in while loop and
never returns.
When I use 2nd CLI Arg statement, CLI.exe returns with value 1.
Now here is the scenario what I observed:
When I use 1st CLIarg statement there is no output on console and
foo.txt
When I use 2nd CLIArg statement redirection takes place in foo.txt.
So could anyone tell me that, Is there any condition that executable
must return a value for redirecting the STDOUT to a file.
If there is no such condition for redirection then what is the problem
in my code???
Please help me out.
Thanks a lot in advance.
Regards
Sachin
Re: Problem in redirection
am 26.08.2007 14:10:18 von Sisyphus
"sachin" wrote in message
news:1188031490.199973.199410@x35g2000prf.googlegroups.com.. .
..
..
>
> When I use 1st CLIArg statement, CLI.exe remains in while loop and
> never returns.
It's therefore conceivable that nothing gets written to STDOUT ... or
rather, it's therefore conceivable that nothing gets written to foo.txt
(since STDOUT has been redirected to foo.txt).
> When I use 2nd CLI Arg statement, CLI.exe returns with value 1.
>
>
> Now here is the scenario what I observed:
> When I use 1st CLIarg statement there is no output on console and
> foo.txt
As expected ... or is there something that CLI.exe is doing that makes you
expect some output even though CLI.exe is stuck in a while loop ?
Incidentally, have you verified that CLI.exe is stuck in the "while loop".
Maybe it's stuck somewhere else ?
Have you verified that it's CLI.exe (and not the perl script) that's stuck ?
> When I use 2nd CLIArg statement redirection takes place in foo.txt.
My feeling is that redirection also takes place when you use the 1st arg ...
but in that case there is simply nothing to redirect.
>
> So could anyone tell me that, Is there any condition that executable
> must return a value for redirecting the STDOUT to a file.
> If there is no such condition for redirection then what is the problem
> in my code???
It has taken me a few minutes to work out what you are asking. You want to
verify that redirection has been successfully achieved, right ?
I think you could do that with:
open STDOUT, '>', "foo.txt" or die "STDOUT has not been redirected: $!";
(as is the usual way to verify that the opening of a filehandle has been
successful :-)
As I said, I would think that redirection has been successfully achieved
..... it's probably just that the hang that occurs with the first arg means
that *nothing* gets output.
Cheers,
Rob
Re: Problem in redirection
am 27.08.2007 06:34:57 von Sachin
On Aug 26, 5:10 pm, "Sisyphus" wrote:
> "sachin" wrote in message
>
> news:1188031490.199973.199410@x35g2000prf.googlegroups.com.. .
> .
> .
>
>
>
> > When I use 1st CLIArg statement, CLI.exe remains in while loop and
> > never returns.
>
> It's therefore conceivable that nothing gets written to STDOUT ... or
> rather, it's therefore conceivable that nothing gets written to foo.txt
> (since STDOUT has been redirected to foo.txt).
>
> > When I use 2nd CLI Arg statement, CLI.exe returns with value 1.
>
> > Now here is the scenario what I observed:
> > When I use 1st CLIarg statement there is no output on console and
> > foo.txt
>
> As expected ... or is there something that CLI.exe is doing that makes you
> expect some output even though CLI.exe is stuck in a while loop ?
>
> Incidentally, have you verified that CLI.exe is stuck in the "while loop".
> Maybe it's stuck somewhere else ?
> Have you verified that it's CLI.exe (and not the perl script) that's stuck ?
>
> > When I use 2nd CLIArg statement redirection takes place in foo.txt.
>
> My feeling is that redirection also takes place when you use the 1st arg ...
> but in that case there is simply nothing to redirect.
>
>
>
> > So could anyone tell me that, Is there any condition that executable
> > must return a value for redirecting the STDOUT to a file.
> > If there is no such condition for redirection then what is the problem
> > in my code???
>
> It has taken me a few minutes to work out what you are asking. You want to
> verify that redirection has been successfully achieved, right ?
>
> I think you could do that with:
>
> open STDOUT, '>', "foo.txt" or die "STDOUT has not been redirected: $!";
>
> (as is the usual way to verify that the opening of a filehandle has been
> successful :-)
>
> As I said, I would think that redirection has been successfully achieved
> .... it's probably just that the hang that occurs with the first arg means
> that *nothing* gets output.
>
> Cheers,
> Rob
Hi Rob
I think I am not able to explain my problem properly.
It is known that
1) the hangs occur in CLI.exe and not in perl script.
2) When CLI.exe stucks then also it sends some traces on console(If no
redirection ststement is written).
Now when I use CLI.exe with 1st statement for CLIArg ,it stucks and it
does not redirect the console output in foo.txt.
But when I use without redirection it shows me output on console.
So why am I not getting console output in foo.txt when redirectd in
case of CLI.exe stucks
Re: Problem in redirection
am 27.08.2007 09:05:47 von Sisyphus
"sachin" wrote in message
..
..
> It is known that
> 1) the hangs occur in CLI.exe and not in perl script.
> 2) When CLI.exe stucks then also it sends some traces on console(If no
> redirection ststement is written).
What happens when the redirection statement is included ? Do you still see
those "traces" on the screen ? If so, then they are probably being written
to STDERR (which has not been redirected).
But if the "traces" vanish completely (with redirection turned on), then I
cannot think of an explanation.
Anyway, I would also try redirecting STDERR to another (different) file and
see if that makes any difference.
Cheers,
Rob
Re: Problem in redirection
am 05.09.2007 07:42:58 von Sachin
On Aug 27, 12:05 pm, "Sisyphus" wrote:
> "sachin" wrote in message
>
> .
> .
>
> > It is known that
> > 1) the hangs occur in CLI.exe and not in perl script.
> > 2) When CLI.exe stucks then also it sends some traces on console(If no
> > redirection ststement is written).
>
> What happens when the redirection statement is included ? Do you still see
> those "traces" on the screen ? If so, then they are probably being written
> to STDERR (which has not been redirected).
>
> But if the "traces" vanish completely (with redirection turned on), then I
> cannot think of an explanation.
>
> Anyway, I would also try redirecting STDERR to another (different) file and
> see if that makes any difference.
>
> Cheers,
> Rob
Hi Rob
Sorry for my late reply.
When I use 1st CLI arg and include redirection statement,then traces
vanishes completely on console.
Re: Problem in redirection
am 05.09.2007 15:45:46 von Sisyphus
"sachin" wrote in message
..
..
> Sorry for my late reply.
No problem
> When I use 1st CLI arg and include redirection statement,then traces
> vanishes completely on console.
And they don't appear in foo.txt either ??
That's strange ... I don't have an explanation.
All I can suggest is that you try posting to perlmonks (
http://www.perlmonks.org/index.pl?node=Seekers%20of%20Perl%2 0Wisdom ) where
you'll reach more people (and thus a broader range of expertise).
It would probably help your cause if you could demo the problem using only
perl files - ie instead of having Win32::Process run CLI.exe, have it run a
perl file (say, CLI.pl). It's not hard to simulate a hanging program that
produces output to stdout and stderr:
----------------------------------------------
use warnings;
my $x = 0;
while(1) {
if($x % 5000000 == 0) {
warn "This printed to STDERR\n";
print "This is printed to STDOUT\n"
}
$x++;
}
----------------------------------------------
Cheers,
Rob