SPUG: system() eating STDIN, how to avoid?

James Moore james at banshee.com
Thu Jun 30 19:48:15 PDT 2005

I've got some code that reads from STDIN.  Occasionally this code needs to
call system() to generate an audio file.

Something in the system() call seems to be eating from standard input,
though.  If I stop in the debugger right before the system() call, and do


I see all the remaining input that I expect.  And at this point I understand
that that input has been eaten, so I restart.  If I step through the
system() call, then do the same


I see 

  DB<89> x <STDIN>
  empty array

I've tried things like replacing the command I intend to run inside system()
with system('ls') and get the same results, which surprised me.

I tried it with system('ls < /dev/null > /dev/null') and also got the same
results (nothing left in STDIN after system().

What am I missing here?  What's the right way to protect STDIN?  Note that I
don't want the thing run in the system() call to have access to this input.

- James

More information about the spug-list mailing list