Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Backticks and SIGALRM

by Anno (Deacon)
on Aug 20, 2007 at 11:39 UTC ( #633773=note: print w/replies, xml ) Need Help??


in reply to Backticks and SIGALRM

I can't reproduce that result. In particular, using the external command
`echo start; sleep 5; echo done`
I see the expected timeout. With
`echo start; sleep 0; echo done`
the result is the two echoed lines, again as expected.

Anno

Replies are listed 'Best First'.
Re^2: Backticks and SIGALRM
by nemo (Sexton) on Aug 20, 2007 at 11:44 UTC
    Yes
    I have tested the alarm code in isolation using an infinite loop and it does work as expected. The alarm timeout works correctly when the external app is executed using "system" but as I need to collect the output I cannot use it.
    Thank you for your reply.

    Nemo
      Can I pipe the output of the system command to my own program and read it in line by line. That way getting the best of both?
        Yes, you can pipe the output of the system command to [your] own program. In perldoc -f open, see the paragraphs following
        If the filename begins with '|' ...
        Anno

        as you are using qx() (which gets the full output anyway) maybe you can simply redirect the output of your external command to a file (using the system shell and process that later

        my $cmd = "$ext_cmd > $my_output"; # using unixlike shell system($cmd) == 0 or die; #

        (ignore if your OS is not unixlike) what does happen if you manually send SIGALRM to that external process? (wrap it in a shell if the execution time is too short).

        cheers --stephan
      When did system() enter the equation? I tested your code using backticks and it works as expected.

      Anno

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://633773]
help
Chatterbox?
marioroy On a large dairy farm, almost went off the road with a 10 wheeler from exhaustion. On the farm, almost went off the silo with a big tractor. At the Fransiscan monastery, almost slipped off the dome while painting it.
[marioroy]: In Saudi Arabia caught fire but didn't burn. I think angels exist.
Lady_Aleena clean up after dinner finally.
[Discipulus]: uch! so we are twice lucky to have MCE..;=)
[marioroy]: Working a midnight graveyard shift, on the way home ran out of gas. just 2 minutes later somebody stops with a small tank of gas. It's wierd. There's always someone nearby for some reason.
[Lady_Aleena]: I was the one who stop[ed in the middle of a cold night to pick up a small family walking to a gas station. I got a few gallons of free gas for the round trip, and the grandmother said she'd pray for me.
[marioroy]: Folks do not know it, but MCE was ridiculously difficult. At Niagra Falls, heard a voice on enabling Grace while in the mist boat. That 10x performance is possible.
[marioroy]: Lady_Aleena Angels on earth are real people. That's awesome.
[Lady_Aleena]: marioroy, what does MCE stand for in this instance? There are 3 pages of abbreviations to go through.
[Lady_Aleena]: ^ or Discipulus...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2017-05-29 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?