How to make STDOUT unbuffered, please guide me

S

sahana H V

Hi,

Can i make stdout associated with my own file handle as unbuffered ?
If so can you please tell me how to do it?

What i am trying to do is:

open (HVS, "/<command> <cmnd_args> 2>&1 |"); <==
at this point of time i need stdout to be unbuffered .so that command output
should be logged to HVS in unbuffered fashion.

Thanks,
-Sahana
 
D

david

Hi,

Can i make stdout associated with my own file handle as unbuffered ?
If so can you please tell me how to do it?

What i am trying  to do is:

open (HVS, "/<command> <cmnd_args> 2>&1 |");   <==
at this point of time i need stdout to be unbuffered .so that command output
should be logged to HVS in unbuffered fashion.

Thanks,
 -Sahana

perldoc -q unbuffer
 
J

Josef Moellers

sahana said:
Hi,

Can i make stdout associated with my own file handle as unbuffered ?
If so can you please tell me how to do it?

What i am trying to do is:

open (HVS, "/<command> <cmnd_args> 2>&1 |"); <==
at this point of time i need stdout to be unbuffered .so that command output
should be logged to HVS in unbuffered fashion.

You can't, unless you have control over the command.

It's the binary of the command (more precise: the stdio library linked
to the command) which does the buffering and if stdout is not connected
to a terminal (and a pipe is *not* a terminal), it will buffer its output.

Josef
 
J

Josef Moellers

Ben said:
You could try using IO::Run's ">pty>" syntax, or using a pty yourself.

Maybe Expect is an option if the OP needs to parse the command's output.

Josef
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top