Professional Web Applications Themes

Problem in redirection - PERL Modules

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\commandli netoolset\ \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 ...

  1. #1

    Default Problem in redirection

    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\\commandli netoolset\
    \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

    sachin Guest

  2. #2

    Default Re: Problem in redirection


    "sachin" <com> wrote in message
    news:googlegroups.com...
    ..
    .. 

    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).
     

    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 ?
     

    My feeling is that redirection also takes place when you use the 1st arg ...
    but in that case there is simply nothing to redirect.
     

    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

    Sisyphus Guest

  3. #3

    Default Re: Problem in redirection

    On Aug 26, 5:10 pm, "Sisyphus" <afraid.org> wrote: 
    >
    > 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).


    >
    > 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 ?

    >
    > My feeling is that redirection also takes place when you use the 1st arg ...
    > but in that case there is simply nothing to redirect.
    >
    >

    >
    > 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[/ref]

    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

    sachin Guest

  4. #4

    Default Re: Problem in redirection


    "sachin" <com> wrote in message
    ..
    .. 

    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

    Sisyphus Guest

  5. #5

    Default Re: Problem in redirection

    On Aug 27, 12:05 pm, "Sisyphus" <afraid.org> wrote: 
    >
    > 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[/ref]

    Hi Rob
    Sorry for my late reply.
    When I use 1st CLI arg and include redirection statement,then traces
    vanishes completely on console.

    sachin Guest

  6. #6

    Default Re: Problem in redirection


    "sachin" <com> wrote in message
    ..
    .. 

    No problem
     

    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%20Wisdom ) 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

    Sisyphus Guest

Similar Threads

  1. Redirection Problem
    By Topspin in forum PHP Programming
    Replies: 4
    Last Post: February 2nd, 07:16 AM
  2. Problem with header redirection but only with IE
    By Ian in forum PHP Development
    Replies: 2
    Last Post: January 14th, 11:38 AM
  3. Passport Redirection Problem.
    By Munna in forum ASP.NET Security
    Replies: 2
    Last Post: July 14th, 10:06 AM
  4. header() redirection/session variable problem
    By Nick Whitelegg in forum PHP Development
    Replies: 1
    Last Post: September 17th, 07:39 PM
  5. Problem with redirection in a Form...
    By Calvin in forum ASP
    Replies: 2
    Last Post: July 15th, 01:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139