Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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:

Hi,
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);

Comment on wait for the system command to complete process
Download Code
Re: wait for the system command to complete process
by kcott (Abbot) 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 (Parson) on Sep 13, 2012 at 13:54 UTC

    kulls,

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://993362]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-09-02 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (18 votes), past polls