×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Piping STDOUT and STDIN

Piping STDOUT and STDIN

Piping STDOUT and STDIN

(OP)
Hey,

   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.

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.

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)  the parser keeps outputting newlines. This could be the logic in my parser, simplified it looks like:


while ($data ne "#")
{
    $data = getc STDIN;
    print "data is: $data";
}


which gives me (for an entered value of '12345'):


data is:1
data is:2
data is:3
data is:4
data is:5
data is:
data is:
data is:
data is:


Which carries on till I interrupt the parser with a ^C.

Is there some kind of flushing that I need to do, or should I try and capture \n to stop getc. Is it because there is nothing to read?

Any help appreciated.
Loon

RE: Piping STDOUT and STDIN

As far as I can tell getc should not return without a character for you - unless you are setting some weird(ish) stty modes

What platform are you on (unix I guess, with fork)?

Are you setting stty at all?

Is there any data being returned on those blank line?

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site

RE: Piping STDOUT and STDIN

(OP)
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.

I'll play about with it again today and see if I can trap what is being returned on those blank lines.

Cheers
Loon

RE: Piping STDOUT and STDIN

(OP)
Mike,

    cheers mate! That did the trick. Still not quite sure what logic was being mucked about in the While - seems simple enough.

    Anyway that now works fine!

Thanks again
Loon

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close