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

I have an executable that I have been running like so

$num = `$prog_path/prog.exe $srvname $state $fault`

The prog.exe returns a number that I want to catch in $num.
I would like to use Win32::Process::Create. The reason is that I would like to utilise the $ProcessObj->Wait($timeout) feature and kill the process if it times out. My problem... I have no idea how to get the number that the prog.exe returns back to $num.
This is what I have tried.

$num = Win32::Process::Create($ProcessObj, $prog_path/prog.exe, prog $ +srvname $state $fault,0,DETACHED_PROCESS);

The above code WITHOUT the $num = runs the program as a seperate process, but I need the number that is returned...

any ideas..?

Many Thanks
Sean
-----
Of all the things I've lost in my life, its my mind I miss the most.

Replies are listed 'Best First'.
Re: Win32 Process Output
by dada (Chaplain) on Jul 18, 2002 at 10:40 UTC
    you have to catch STDOUT. something like this:
    open(OLDOUT, ">&STDOUT"); open(OUTPUT, ">processlog"); open(STDOUT, ">&OUTPUT"); $| = 1; Win32::Process::Create($ProcessObj, @args); $ProcessObj->Wait( $appropriate_amount_of_time ); close(OUTPUT); close(STDOUT); open(STDOUT, ">&OLDOUT");
    at this point, you can open the processlog file and read $num from there.

    there may be smarter ways to do it without writing to a file, but I haven't time to look up something for you :-)

    cheers,
    Aldo

    __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;