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

In Perl, I kick off a command line exe that sends data to
STDOUT. I want to catch all those bits:

Win32::Process::Create ( $ProcessObj2, $counters_fname, "$COUNTERS_NAME -interval $interval", 1, NORMAL_PRIORITY_CLASS, "." ) || HandleProcess_Failure($COUNTERS_NAME); $ProcessObj2->Suspend(); $ProcessObj2->Resume();
After that, I need to do an open(), open2() or open3(),
followed by the while loop to read data...I cannot get it to work.
I dont need to write to the exe, just capture stdout.
I will even let STDERR go to cmd shell.

Any help? I am hoping for the exact open command to
use...I have found lots of "stuff" but it's not workable code.

Replies are listed 'Best First'.
Re: capturing STDOUT after Win32::Process::Create()
by ikegami (Patriarch) on Nov 30, 2004 at 15:17 UTC

    open2 / open3 is something that can be done instead of CreateProcess.

    If you're not feeding anything to it using STDIN, you can simply use:

    open(COUNTER, "$COUNTERS_NAME -interval $interval |") or die("...: $!\n"); while (<COUNTER>) { ... }
      I was afraid of that...the problem is, I have to "Wait"
      after $COUNTERS_NAME executes for one minute. If I use your
      open command, I won't be able to execute another perl command
      while $COUNTERS_NAME executes...

      Can I set STDOUT to go to a file before calling
      Win32::Process::Create(), then set it back when done?
      Thanks so far, your comment cleared up a confusing
      post from a less prestigious source...
        If I use your open command, I won't be able to execute another perl command while $COUNTERS_NAME executes...

        Not true, you can.

        I have to "Wait" after $COUNTERS_NAME executes for one minute.

        You can use sleep(60), or poll time, ...

        Can I set STDOUT to go to a file before calling Win32::Process::Create(), then set it back when done?

        I think you could execute cmd /c mycommand args > outputfile instead of just mycommand args