http://www.perlmonks.org?node_id=633775


in reply to Re: Backticks and SIGALRM
in thread Backticks and SIGALRM

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

Replies are listed 'Best First'.
Re^3: Backticks and SIGALRM
by nemo (Sexton) on Aug 20, 2007 at 11:51 UTC
    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
Re^3: Backticks and SIGALRM
by Anno (Deacon) on Aug 20, 2007 at 13:12 UTC
    When did system() enter the equation? I tested your code using backticks and it works as expected.

    Anno