For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > December 2006 > system() command with a time limit









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author system() command with a time limit
Kelly Jones

2006-12-24, 9:58 pm

I want to use system() (or `command`) to run an external command from
my Perl script. However, if the external command takes more than 30
seconds (for example) to run, I want to kill it, and move on with the
rest of my Perl script. How do I do this?

--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.
Jeff Pang

2006-12-24, 9:58 pm

Using eval.

eval {
local $SIG{ALRM} = sub {die "something is wrong"};
alarm 30;
do_something...
alarm 0;
};

if ($@) {
handle_for_the_errors();
}

-----Original Message-----
>From: Kelly Jones <kelly.terry.jones@gmail.com>
>Sent: Dec 25, 2006 9:45 AM
>To: beginners@perl.org, perl-beginner@egroups.com
>Subject: system() command with a time limit
>
>I want to use system() (or `command`) to run an external command from
>my Perl script. However, if the external command takes more than 30
>seconds (for example) to run, I want to kill it, and move on with the
>rest of my Perl script. How do I do this?
>
>--
>We're just a Bunch Of Regular Guys, a collective group that's trying
>to understand and assimilate technology. We feel that resistance to
>new ideas and technology is unwise and ultimately futile.
>
>--
>To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>For additional commands, e-mail: beginners-help@perl.org
><http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>



--
Books below translated by me to Chinese.
Practical mod_perl: http://home.earthlink.net/~pangj/mod_perl/
Squid the Definitive Guide: http://home.earthlink.net/~pangj/squid/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com