command pipe concatenated messages

Jim Mozley jim.mozley at exponential-e.com
Mon Dec 29 11:41:27 CET 2003


Stanley Hopcroft wrote:



>>I should be writing less than PIP_BUF bytes, although I'm not 
>>specifically checking. In the case where I can see the concatenation of 
>>messages it is always less that the max amount. In fact I haven't seen 
>>any messages greater than this.
>>
> 
> 
> you won't - all of the IO (both system and Perl) - requires the coder to
> explicity check for errors.

Yep, I understand this. I could be paranoid and check the message length 
and truncate if beyond a certain size, but I know these are syslog 
messages and are less than the PIP_BUF size by their nature.

>>I am using print to output the message to the pipe as I am using open. 
>>If I was using sysopen I guess I'd use syswrite. Is this what you mean?
>>
> 
> 
> This may be useful: 
> 
> My understanding is 
> 
> 1 print always uses (buffered) stdio; syswrite is simply a badly named
> Perl interface to the system (unbuffered) write() system call.

Presumably as opposed to the perl write function, which I think also 
uses buffered I/O.

> 
> Never use print with things like sockets and multi-user pipes.
> 
> 2 sysopen is simply another interface to the open() system call.
> 
> Unlike Perl open, it has no magic (eg read from or  to pipes), and lets
> you sepcify file modes and stuff.
> 
> If you haven't already done so, you may like to consider 
> 
> 1 ignoring sys?open
> 
> 2 s/print/write()/g

Checking the perldoc in light of your suggestions I found syswrite does 
unbuffered I/O. So I'll change the print to syswrite and failing this I 
can change $| as in perlfaq5.

Thanks for the help,

Jim



-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click




More information about the Developers mailing list