manojkumar89 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am running a system command from my perl script which looks like system("collect_stats 20 11 > file1"); the output of the above collect_stats will take some time. output will be printed in line by line fashion with some time intervals between each line. it will look like. .... calculating 100 200 300 1000 123 done calculating. But only the first line is saved in file1. remaining are not being saved in the file. Please help me out. Thanks, Manoj
  • Comment on Increasing the timeout of a system command in perl

Replies are listed 'Best First'.
Re: Increasing the timeout of a system command in perl
by Random_Walk (Prior) on Jan 07, 2014 at 11:48 UTC

    There is no 'timeout' on a system command. If it hangs forever, Perl will wait forever. Are you sure collect_stats is completing OK? Perhaps you could open it with a pipe for stdout, and use a while loop to print out the lines as you get them. If you try using the while loop, use $|++ to disable buffering.

    If you post an example of working code, that exhibits your problem, then you may get a more useful reply

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!
Re: Increasing the timeout of a system command in perl
by NetWallah (Canon) on Jan 07, 2014 at 15:03 UTC
    Another possibility is that the "collect_stats" script sends most of it's output to STDERR.

    To account for that, try:

    system("collect_stats 20 11 > file1 2>&1");

            If your eyes hurt after you drink coffee, you have to take the spoon out of the cup.
                  -Norm Crosby

Re: Increasing the timeout of a system command in perl
by karlgoethebier (Abbot) on Jan 07, 2014 at 19:26 UTC

    See IPC::Run for timeouts on system commands.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»