Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: print output from system command in real time

by moot (Chaplain)
on May 10, 2005 at 18:34 UTC ( [id://455710]=note: print w/replies, xml ) Need Help??


in reply to print output from system command in real time

You could try something like
open SYS, "command |" or die "$!"; while (<SYS>) { print } close SYS;
but a lot depends on whether 'command' buffers its output, among other variables. You should probably read perldoc perlipc for more insight.

Replies are listed 'Best First'.
Re^2: print output from system command in real time
by boat73 (Scribe) on May 10, 2005 at 18:53 UTC
    Thanks but that did not work. I built a standalone exe from the following code. Oh and I am doing this on windowz to make it even more fun.
    until($cnt == "100"){ print "COUNT IS $cnt\n"; sleep 5; $cnt++; }
    I then call the exe within perl. With the code you supplied it still waits until completion before printing. I even tried setting autoflush with the code below.
    open SYS, "c:\\temp\\junk.exe |" or die "$!"; $oldfh=select(SYS); $| = 1; select($oldfh); $| = 1; while (<SYS>) { print } close SYS;
        Hmmm, the problem is that the exe I am truly running does the same thing and I am unable to modify that code. System didn't work, still waits til completion to print.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://455710]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-19 10:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found