Controlling stdin and stdouts of other executables

Brad Appleton brad at SSD.CSD.HARRIS.COM
Mon May 7 04:48:26 AEST 1990


In article <6418 at star.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>
>It's *WRONG* to close an arbitrary program's standard streams!

The program being called is NOT arbitrary, the coder knows which command
is to be called. 

>Suppose the program checks the return value of printf() - if stdout is
>closed, printf() will return EOF, so the program might decide something
>is terribly wrong, and terminate!

But output will still have been (successfully) ignored :-)

>You don't want to close the standard streams, you want to connect them
>to /dev/null, quite a difference!

Agreed! I personally would have connected output to /dev/null myself.
Perhaps I should have posted a solution using "dev/null" instead but I
was trying to give an easy example (which works just fine on my System BTW).
You are right in that I probably should have used /dev/null.

>Bonus: the `0' in the execlp() call should be `(char *) 0'; grrrr, when
>do people ever learn?  :-(

GRRRRRR yourself! I used it the way it was documented for my system!!!!
I originally had used NULL (which is preferred over (char *) 0) instead of
0 but My reference text used 0 (not (char * 0))! My system may be slightly
different than yours, but I did use the proper type according to my FM.
(Of course, it could be a problem in the FM :-)

-=-=-=-=-=-=-=-=-=-=-= "And miles to go before I sleep." =-=-=-=-=-=-=-=-=-=-=-
 Brad Appleton         Harris Computer Systems         brad at ssd.csd.harris.com
 (305) 973-5360        Fort Lauderdale, FL USA        {uunet,novavax}!hcx1!brad
-=-=-=-=-=-=-=-=-=-= Disclaimer: I said it, not my company! -=-=-=-=-=-=-=-=-=-



More information about the Comp.lang.c mailing list