Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

wait for the system command to complete process

by kulls (Hermit)
on Sep 13, 2012 at 04:53 UTC ( #993362=perlquestion: print w/replies, xml ) Need Help??
kulls has asked for the wisdom of the Perl Monks concerning the following question:

Below code reads the output of the nmon system command. the script starts executes before system command complete its processing and parsing only half of the file.
Is there any work around other than using sleep command ?
my $result= `nmon -F file.out -s3 -c1`; open(FILE,"<file.out") || die $!; while(<FILE>) { print $_; } close(FILE);

Replies are listed 'Best First'.
Re: wait for the system command to complete process
by kcott (Chancellor) on Sep 13, 2012 at 05:29 UTC

    G'day kulls,

    I'm not an nmon user and I don't have it installed so I can't test any of the following.

    My understanding is that nmon starts a daemon so the command will return before the daemon finishes. That would be why you're only getting part of the output.

    You don't show any use of $result: I suspect system would be a better choice than backticks.

    If you are only running it for a few seconds (-s3 -c1), then sleep may be a viable option; however, I'd probably lean more towards tailing file.out - File::Tail may be helpful for that.

    -- Ken

Re: wait for the system command to complete process
by flexvault (Monsignor) on Sep 13, 2012 at 13:54 UTC


    I'm not sure I understand the problem, but I ran your code and it finished as fast as I typed the command. So if you use 'system':

    my $result = system(`nmon -F file.out -s3 -c1`);
    'system' will wait until the command completes and returns.

    Hope it helps...Ed

    "Well done is better than well said." - Benjamin Franklin

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://993362]
Approved by kcott
[marto]: hmm, I wonder who is actually checking for such things

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-01-18 11:03 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (211 votes). Check out past polls.