Hirosi Taguti writes: > I hear that Win32 cann't use "alarm" for a timeout. > The sample code in Camel book or Cookbook is not valid > on Win32. Is this true even now?
Yes, alarm() on Windows will not interrupt a blocking system call. > I must execute some external command by @rc = `SOME.exe`, > which may hung sometimes. > These are SQLPLUS and FTP and any with -B(atch) option. > Sometimes I can do by DBI and Net::FTP and... but sometimes > I don't have a work-around. > > Any idea? If you are using Windows 2000 or later you can use the Job subsystem to set a time limit on the subprocess. Here is a simple job.pl script that executes any command, but only for a specified number of seconds: use Win32::Job; my $job = Win32::Job->new; my $timeout = shift; my $exe = $ARGV[0]; s,",\\",g, ($_ = qq("$_")) for @ARGV; $job->spawn($exe, "@ARGV"); $job->run($timeout); Here is a sample run to limit an endless loop to 5 seconds: C:\>job.pl 5 perl -le "while(){print $i++; sleep 1}" 0 1 2 3 4 Look at the documentation of the Win32::Job module to see how you can use it with redirected file handles to capture output from the script without using temporary files. But don't try to redirect both STDIN and STDOUT; you'll most likely end up blocking the child process due to IO buffering issues. Cheers, -Jan
<<attachment: winmail.dat>>
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs