简体   繁体   中英

Time out for external process completion in perl (windows)

I'm writing a perl program for windows, that runs several SVN commands.

I need to receive the status of the SVN process so i'm using "back ticks".

eg:

{
$COMMAND="blabla...";
$results=`$COMMAND 2>&1`;
parse_results($results);
}

Sometimes the process gets stuck, so I need to set timeout to the process.

I tried to use "ALARM" signal but it didn't kill the stuck process. I receive the indication only if and when the process finishes.

What can I do to deal with processes that don't complete fast enough?

Signals are a unix concept. Instead, you should use IPC::Run .

use IPC::Run qw( run timeout );

run [ 'bla', 'arg' ], '>&', \my $results, timeout( 10 )
   or die "bla: $?"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM