Re: Win32 and alarm
Another way to do it is to spawn a thread and do the command there and return the pid to the main thread. That way u can monitor the command and get it's output. If it hangs, u can kill it from the other thread. -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32 and alarm
> 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); > I didn't know Win32::Job! Nice to hear it... Regards, HT ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32 and alarm
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 <>___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32 and alarm
Sisyphus wrote: > I don't think ActiveState *can* implement wait() to handle processes > launched with backticks. But they already provide you with the > Win32::Process module, which is the correct course of action ot take. > > If I understand you correctly, you can just use Win32::Process's Wait() and > Kill() functions to implement the alarm - if the executable is launched > using Win32::Process's Create() function. > > I don't see a need for either Time::HiRes or output redirection (though I > could be missing something). HiRes for timing the kill (although time maybe be close enough for the poster [I'm assuming looping on a small wait]) and redirection to get the output of the child (imitating backticks). ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32 and alarm
> >>`` is blocking, so maybe use Win32::Process and time it with > >>Time::HiRes. You may need to redirect the output to a file. ... > Once you've done it, save the code and you don't have to ever re-do > it again. Yes true, but "My" code may have bugs. :-) I wonder if someone up as a CPAN module so-called Win32-Backtick. @rc = Win32::Backtick('MySome.exe -B'); Regards, HT ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32 and alarm
- Original Message - From: <[EMAIL PROTECTED]> To: Sent: Wednesday, November 29, 2006 2:30 PM Subject: RE: Win32 and alarm > > `` is blocking, so maybe use Win32::Process and time it with > > Time::HiRes. You may need to redirect the output to a file. > > sounds a heavy task. > Any possibility to wait for ActiveState implementing it? > I don't think ActiveState *can* implement wait() to handle processes launched with backticks. But they already provide you with the Win32::Process module, which is the correct course of action ot take. If I understand you correctly, you can just use Win32::Process's Wait() and Kill() functions to implement the alarm - if the executable is launched using Win32::Process's Create() function. I don't see a need for either Time::HiRes or output redirection (though I could be missing something). Cheers, Rob ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32 and alarm
[EMAIL PROTECTED] wrote: >>`` is blocking, so maybe use Win32::Process and time it with >>Time::HiRes. You may need to redirect the output to a file. > > > sounds a heavy task. > Any possibility to wait for ActiveState implementing it? They sorta have, but since the OS doesn't support it, it's a kludge and not reliable in many instances. Not that hard to start a process and redirect output to a file and read the file after the timeout expires or the task completes. Once you've done it, save the code and you don't have to ever re-do it again. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32 and alarm
> `` is blocking, so maybe use Win32::Process and time it with > Time::HiRes. You may need to redirect the output to a file. sounds a heavy task. Any possibility to wait for ActiveState implementing it? Regards, HT ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32 and alarm
[EMAIL PROTECTED] wrote: > Hello, > > 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? > > 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? `` is blocking, so maybe use Win32::Process and time it with Time::HiRes. You may need to redirect the output to a file. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Win32 and alarm
Hello, 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? 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? Regards, Hirosi Taguti ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs