Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

wait for the system command to complete process

by kulls (Hermit)
on Sep 13, 2012 at 04:53 UTC ( [id://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);

Replies are listed 'Best First'.
Re: wait for the system command to complete process
by kcott (Archbishop) 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

    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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-19 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found