Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

real time open(HANDLE,"cmd |");

by rouge (Initiate)
on Nov 07, 2009 at 15:59 UTC ( #805648=perlquestion: print w/replies, xml ) Need Help??
rouge has asked for the wisdom of the Perl Monks concerning the following question:

Hi ! i'm using open(HANDLE,"cmd |") (with a while(<HANDLE>) {...}) to read and parse what the command "cmd" write to its standard output (simple and logic). My problem is that the commands writes really few datas to STDOUT, and the open (or the pipe ? or the way the "while(<HANDLE>)" is handled by perl ?) is buffered, so i sometimes have to wait about 1 or 2 minutes to have my perl program getting the datas... Is there any simple way to get that stuff being unbuffered (or to flush the buffer, or any other magic thing) ? if there's no easy way, i can still rewrite it "C fashion", with fork and exec, but i'm still not sure if the stdout will be automattically buffered or not... help meeeee !!!

Replies are listed 'Best First'.
Re: real time open(HANDLE,"cmd |");
by jettero (Monsignor) on Nov 07, 2009 at 16:03 UTC
Re: real time open(HANDLE,"cmd |");
by zwon (Abbot) on Nov 07, 2009 at 16:10 UTC

    I think that it's cmd buffering its output, so here's not too much you can do in perl. Fix cmd to flush it's buffer after every output operation if you can.

      About the only thing you can do is fool the program into thinking its connected to a tty rather than a pipe. That will cause most programs to use line buffering. Look into using a pseudo tty. IPC::Run can help there.
        A windows console handle (CONIN$, CONOUT$) is not a pipe handle, it is a character device file handle (TTY handle) to the console input buffer or a console output buffer.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://805648]
Approved by Corion
help
Chatterbox?
[Lady_Aleena]: The default perl on the version of cPanel my web hosts uses is 5.8.8 which means I am dreadfully behind. I doubt perl 6 will hit my web host in my lifetime.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2017-05-29 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?