in reply to IPC::Open3 buffering and autoflush

I think the camel book answers your question quite nicely, so I'll simply just quote directly from it.

The problem with standard I/O buffering is though your output filehandle is autoflushed so the process on the other end will see your data in a timely manner, you can't usually do anything to force it to return the favor. In some cases, for example "bc -l", it expects to operate over a pipe so therefor it flushes each output line, but it often seldom works this way unless you wrote the program yourself ( As you did with the script and turned off buffering on STDOUT). Various interactive programs also fail here, like FTP which wont do line buffering on a pipe, only on a TTY device.

As mentioned, the IO::Pty and Expect modules provide a pseuedo-tty device, giving you line-buffering without needing to modify the program on the end of the pipe.

Replies are listed 'Best First'.
Re^2: IPC::Open3 buffering and autoflush
by morpheus (Initiate) on Jan 07, 2010 at 13:55 UTC

    Thanks for the suggestions. My main goal is to just log the output, grep different strings while the called program is running, highlight errors and other stuff. But in some situations I have to provide input. I thought that I could blame open3 because I thought that the called program whould inherit the stdout-filehandle and its properties, so I wrote a wrapper-script

    use IO::Handle; STDOUT->autoflush(1); exec ./program_to_launch

    And then I called the wrapperscript with open3. But it doesnt seem to work. I think I haven't really understand where the buffering actually takes place. I will now take a look at IO::Pty.

    -Stefan