Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://805648]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2018-06-25 04:53 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.