Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utcsri!utegc!rayan From: rayan@utegc.UUCP Newsgroups: comp.unix.wizards Subject: Re: shell stderr in popen() Message-ID: <8708111952.AA03137@ephemeral.ai.toronto.edu> Date: Tue, 11-Aug-87 15:52:41 EDT Article-I.D.: ephemera.8708111952.AA03137 Posted: Tue Aug 11 15:52:41 1987 Date-Received: Wed, 12-Aug-87 05:42:26 EDT References: <4511@sunybcs.UUCP> <8708100615.AA06203@ephemeral.ai.toronto.edu> Distribution: na Organization: University of Toronto, AI group Lines: 41 Checksum: 42494 >In article <7928@mimsy.UUCP> Chris suggests: ># (void) sprintf(expandcmd, "sh -c '%s' 2>/dev/null", command); ># iop = popen(expandcmd, "r"); In article <8708100615.AA06203@ephemeral.ai.toronto.edu> I write: >Seems too expensive. Try > > popen("exec 2> /dev/null ; /usr/bin/mynewcommand -flags", "r"); In article <7932@mimsy.UUCP> Chris replies: # This is a good idea. Unfortunately, it does not work; the shell has # already set its own standard error to another descriptor, so that it # can still print errors. Before posting my suggestion above, I tried it out. I'm on a SunOS 3.4 box, and using exec as shown did indeed get rid of the ": not found" message. But Chris usually knows what he's talking about (too...), so I just tried it on 4.3bsd. There his admonition holds true. Therefore I conclude that early v7-based sh's (as in 4.3bsd) require something like: 1. popen("( /usr/bin/mynewcommand -flags ) 2> /dev/null", "r"); while sysV-based sh's (as in SunOS) will work with: 2. popen("exec 2> /dev/null ; /usr/bin/mynewcommand -flags", "r"); Note that method 1. is less overhead (one less path search and exec), and less problematic vis-a-vis quoting, than the original suggestion at the top of this message. I thought of specifying the fd that the 4.3 sh dup's stderr to, instead of '2'. Unfortunately, that is fd 11, and only single digits may be used to specify the fd for a redirection. I'm glad this feature of juggling the fd's around was removed in sysV (presumably). Live and learn. rayan -- Rayan Zachariassen AI group, University of Toronto