Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!labrea!decwrl!pyramid!prls!mips!dce From: dce@mips.UUCP (David Elliott) Newsgroups: comp.unix.wizards Subject: Re: shell stderr in popen() Message-ID: <574@quacky.UUCP> Date: Fri, 7-Aug-87 11:17:30 EDT Article-I.D.: quacky.574 Posted: Fri Aug 7 11:17:30 1987 Date-Received: Tue, 18-Aug-87 03:02:37 EDT References: <4511@sunybcs.UUCP> Reply-To: dce@quacky.UUCP (David Elliott) Distribution: na Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 44 Keywords: shell popen stderr redirection In article <4511@sunybcs.UUCP> ugbinns@marvin.UUCP (Leonard Binns) writes: >In article <124@foobar.UUCP> tw@foobar.UUCP (Tom Walsh) writes: > >> i have a need to use popen(command, "r"). if command is not >> found, i would like to dispose quietly of the shell's complaint: >> sh: command: not found >> the stderr of the command itself can be handled ala: >> popen("/usr/bin/mynewcommand -flags 2> /dev/null", "r"); >> >> question: >> is there an easier way than: > >Did you ever try: > popen("/usr/bin/mynewcommand -flags 2>& /dev/null", "r"); > ^^^ >I think that should do the trick. Why should it do the trick? It isn't even valid shell syntax! Remember that popen() uses /bin/sh, not your SHELL (and if AT&T changes this, I QUIT!). The >& is used in the sequence m>&n which says "make file descriptor m a duplicate of file descriptor n". The sequence 2>& /dev/null results in "/dev/null: bad file number". Anyway, the easiest way to do this is popen("( /usr/bin/bin/mynewcommand -flags ) 2>/dev/null", "r"); The sequence ( command ) runs the command in a subshell, so all redirection done outside of the parenthesis applies to the subshell. This is also useful in cases like: ( cat file1 ; echo separator ; cat file2 ) | filter -- David Elliott {decvax,ucbvax,ihnp4}!decwrl!mips!dce