avaurus has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to capture the output via the following code:
open(STATUS, "ipconfig |"); while (<STATUS>) { print $_; } close(STATUS);
This snippet does work, but if I pass a parameter it will only get "ipconfig":
open(STATUS, "ipconfig bla1 |"); while (<STATUS>) { print $_; } close(STATUS);
If I execute that script, only the "ipconfig"-part will be executed. Open takes not care about the rest "bla1". I need to mention that this perl-script runs on windows 2000. It would be very nice, if someone can help. Thank you. Dear avaurus.

Replies are listed 'Best First'.
Re: open(), ipc and some problems
by northwind (Hermit) on May 11, 2005 at 16:32 UTC

    Have you tried the three argument form of open?  Which in this case would be:
     open(STATUS, "-|", "ipconfig arguments") or die "ACK, GASP:  Cannot fork: $! ";

      Well, it works :)...Don't know why the other example does not work, but thank you.

        The reason behind this is Windows does not understand the | character on the command line, therefore you need to explicitly declare what are arguments and what is your opening mode.  If you need to be even more explicit (and you're running a Perl > 5.6, I think) you could also say:
         open(STATUS, "-|", "ipconfig", "arg_1", "arg_2") or die "ACK, GASP:  Cannot fork: $! ";

Re: open(), ipc and some problems
by mda2 (Hermit) on May 11, 2005 at 16:54 UTC
    I don't understood your "ipconfig bla1", but suposese a simple argument...

    open(STATUS, "ipconfig /all |"); while (<STATUS>) { print $_ if ( /Physical/ ); } close(STATUS); __END__ Physical. . . . : xx-xx-xx ...

    If only needs to execute ipconfig with parameters its correct. If need other interacts maybe needs try other open forms.

    --
    Marco Antonio
    Rio-PM

      hi, ipconfig bla1 was just an example :)...of course "bla1" does not exist. Thank you.