Win32::Process::Create() - how to capture process output?

Here is the progression of events... (1) I have an open logfile,  (2) I start a process using Win32::Process::Create,  (3) I "Wait" midway through process execution time, then  (4) print other stuff to the logfile.

I need to collect and print the output started at step 2 to the logfile.  I don't mind using a temporary file for storage...but prefer to capture data in memory.  How do I do either of these?  I'm thinking simple redirection to a file in the Process::Create( ) call won't work...but have not tried it.

sub call_it
{
  # ...
  $proc = execute_child($profile);
  proc->Wait (60 * 1000) # wait 1 minute
  print_file_sizes($profile); // prints some other data to the open logfile
  # ...
}
sub execute_child
{
  # ...
  Win32::Process::Create ($ProcessObj2, $proc_fname, "$PROC_NAME -int $interval -samples 3",
    0, NORMAL_PRIORITY_CLASS, "." );  
    # $PROC_NAME runs for 2 minutes - output normally goes to stdout ... its a command line process.
    # I would like to capture this output somehow...?
  # ...
  return $ProcessObj2;
}
mark_at_accAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sstoukCommented:
If you redirect the process output into the file, does it work? if it is, that might  be the simplest method here.

Like:
"$PROC_NAME -int $interval -samples 3 > c:\\proclog.txt"
0
sstoukCommented:
You can as well redirect the STDOUT output for the process into a file.

It is heard to explain it better than it is done here:

http://dbforums.com/archive/95/2002/05/4/387453

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kanduraCommented:
why not use backticks or qx?

    $output = qx/$PROC_NAME -int $interval -samples 3/;

or

    $output = `$PROC_NAME -int $interval -samples 3`;
0
mark_at_accAuthor Commented:
Hi kanduru, I cannot use backticks since I need to be able to continue processing lines in the perl script...using backticks halts the script until the process finishes.

sstouk - I read over http://dbforums.com/archive/95/2002/05/4/387453 and I see the idea, vaguely.  I will pursue coding today or tomorrow, and see how it goes.  Thanks so far...and if you think you understand that page well enough to offer a code snippet, that would be great.  :-)

Mark
0
mark_at_accAuthor Commented:
I was able to make it work with some other help...thanks all.

Mark
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.