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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Piping STDOUT and STDIN

Status
Not open for further replies.

Loon

Programmer
May 24, 2000
100
GB
Hey,<br><br>&nbsp;&nbsp;&nbsp;I am currently writing a parsing program in Perl that interacts with a C process. The C process initially forks() the Perl parser with STDOUT mapped to the parsers STDIN and the parsers STDOUT mapped to the C processes STDIN. <br><br>Because this forking and pipe setup is being done by the C process all my parser needs to worry about is reading from STDIN and writing to STDOUT. For testing purposes the STDOUT redirection hasn't yet been implemented and instead results go to the screen.<br><br>Currently I am having problems with reading STDIN, I get the message but unfortunately as soon as the parser has read it and printed the message to the screen (correctly)&nbsp;&nbsp;the parser keeps outputting newlines. This could be the logic in my parser, simplified it looks like:<br><br><FONT FACE=monospace><br>while ($data ne &quot;#&quot;)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;$data = getc STDIN;<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;data is: $data&quot;;<br>}<br></font><br><br>which gives me (for an entered value of '12345'):<br><br><FONT FACE=monospace><i><br>data is:1<br>data is:2<br>data is:3<br>data is:4<br>data is:5<br>data is:<br>data is:<br>data is:<br>data is:<br></i></font><br><br>Which carries on till I interrupt the parser with a <b>^C</b>.<br><br>Is there some kind of flushing that I need to do, or should I try and capture <b>\n</b> to stop getc. Is it because there is nothing to read? <br><br>Any help appreciated.<br>Loon<br>
 
As far as I can tell getc should not return without a character for you - unless you are setting some weird(ish) stty modes<br><br>What platform are you on (unix I guess, with fork)?<br><br>Are you setting stty at all?<br><br>Is there any data being returned on those blank line? <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>
 
The Processes are running on HP-UX v10.20 and I have not set any stty modes in either program. Nothing (apart from perhaps whitespace - impossible to tell) is being returned, the program just keeps flying through the loop and echoing.<br><br>I'll play about with it again today and see if I can trap what is being returned on those blank lines.<br><br>Cheers<br>Loon
 
Loon<br><br>Try this.<br><FONT FACE=monospace><b><br>while ($data ne &quot;#&quot;)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data = getc STDIN;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;last unless $data;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;data is: $data&quot;;<br>}<br></font></b><br> <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>
 
Mike,<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cheers mate! That did the trick. Still not quite sure what logic was being mucked about in the While - seems simple enough.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Anyway that now works fine!<br><br>Thanks again<br>Loon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top