http://qs321.pair.com?node_id=70141

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

How do I get output and return code, and time-out the process under Win 32?

Originally posted as a Categorized Question.

  • Comment on How do I get output and return code, and time-out the process under Win 32?

Replies are listed 'Best First'.
Re: How do I get output and return code, and time-out the process under Win 32?
by Anonymous Monk on Apr 11, 2001 at 20:59 UTC
    I managed to get it working myself, using something like the following code:
    open ERROR, ">stderr.txt" or die $!; open OUTPUT, ">stdout.txt" or die $!; open SAVEERR, '>&STDERR' or die $!; open SAVEOUT, '>&STDOUT' or die $!; STDERR -> fdopen (\*ERROR, "w") or die $!; STDOUT -> fdopen (\*OUTPUT, "w") or die $!; $create = Win32::Process::Create($processObj, "program.exe", "-args", +1, NORMAL_PRIORITY_CLASS, "."); if ($create != 0) { if ($processObj->Wait(60000)) { $processObj->GetExitCode($result); } else { $processObj->Kill(999); } }
Re: How do I get output and return code, and time-out the process under Win 32?
by ton (Friar) on Apr 06, 2001 at 02:42 UTC
    Backticks will return the output as of Perl 5.6 (at least for the ActiveState distribution). The return code is stored in $?
    $result = `somesyscall`; $retCode = $?;
    Dunno about timing out a process; you might want to look at Win32::Process, which should comes with the ActiveState distribution. You can also find it on CPAN.