Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-23
5
Medium Priority
?
4,203 Views
Last Modified: 2008-10-06
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;
}
0
Comment
Question by:mark_at_acc
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:sstouk
ID: 12659616
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
 
LVL 6

Accepted Solution

by:
sstouk earned 1500 total points
ID: 12659713
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
 
LVL 18

Expert Comment

by:kandura
ID: 12691682
why not use backticks or qx?

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

or

    $output = `$PROC_NAME -int $interval -samples 3`;
0
 

Author Comment

by:mark_at_acc
ID: 12696001
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
 

Author Comment

by:mark_at_acc
ID: 12815636
I was able to make it work with some other help...thanks all.

Mark
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question