Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Buffing on filehandles

Status
Not open for further replies.

sharvey99

Programmer
Aug 24, 2000
16
GB
I have a script which passes a line of formatted data in to an application.

I open the connection to the application thus

open (probe,"| nohup nco_p_generic");
|| die "Cant open probe";

the application can take data on the command line using the format
tokenname "value" tokenname "value" etc as long as the line is terminated with
\n\n the line is passed to the application.

I have a test line in the script which prints out using this format but prints to
STDOUT thus...

print STDOUT "tokenname \"value\" tokenname \"value\""

This works fine and lines are printed as they are recieved (The source of the data is a socket server and lines of data are constanlty flowing from a source client)

When I use the line

print probe "tokenname \"value\" tokenname \"value\""

There appears to be some delay or buffering. The whole thing works but I have to recieve multiple lines or wait 2 minutes not sure which is relevant
before the output lines are sent to the applications handle (probe).

Is there some difference between printing to STDOUT and pipes to applications in the way I have done it.

Thanks in advance for any suggestions

Frustrated Non-programmer but trying !!!

Steve Harvey

[sig][/sig]
 
I think what you are looking for is the output auto_buffer special var, '$|', without the quotes. Try setting $| to 1 which forces a flush of the buffer after every write or print.

$| = 1;

# do what you need and then set it back

$| = 0;

'hope this helps [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo[/sig]
 
Hmmm.....

two things:

1) I think you need to select() the filehandle befoew you set $|
[tt]
select (probe); $|=1; select STDOUT
[/tt]

2) Secind thing is that might not work anyway -- and not through any fault of your own. The process you run on the end of the pipe might very well *not* pay you the same courtesy --- it might leave its output buffered..... So you would never know when you're going to get anything from it... [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Making mistakes, so you don't have to. &lt;grin&gt;[/sig]
 
Thanks for your responses. The combined solutions worked a treat !
No more &quot;Buffing for me this week !!!&quot; [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top