From owner-freebsd-questions Mon Oct 22 0: 7:26 2001 Delivered-To: freebsd-questions@freebsd.org Received: from post.mail.nl.demon.net (post-11.mail.nl.demon.net [194.159.73.21]) by hub.freebsd.org (Postfix) with ESMTP id 0C83E37B401 for ; Mon, 22 Oct 2001 00:07:19 -0700 (PDT) Received: from [195.11.243.26] (helo=Debug) by post.mail.nl.demon.net with smtp (Exim 3.22 #1) id 15vZB8-000G8J-00; Mon, 22 Oct 2001 07:07:18 +0000 To: Joe Clarke , Matthew Blacklow , freebsd-questions@FreeBSD.ORG From: Cliff Sarginson Subject: Re: C clue on FreeBSD Date: Mon, 22 Oct 2001 07:07:18 GMT X-Mailer: www.webmail.nl.demon.net X-Sender: postmaster@btvs.demon.nl X-Originating-IP: 192.250.25.251 Message-Id: Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > > > On Mon, 22 Oct 2001, Joe Clarke wrote: > > > > > > > On Mon, 22 Oct 2001, Matthew Blacklow wrote: > > > > > Hi all, > > > I am running FreeBSD and am trying to learn C. I have a program at the > > > moment which using C's "system" function launches a FreeBSD application. The > > > problem is that it outputs to the screen all the output of the spawned > > > process. I need to know how to supress the output of this process. I have > > > looked through many C programming books and on the web and cant seem to find > > > what i am looking for. > > > > Try: > > > > system("/my/app 2>&1 >/dev/null"); > > Sorry, I should have said: > > system("/my/app >/dev/null 2>&1"); > > For some reason (there may be a good one, though I don't know what it is), > the shell doesn't redirect stderr in the first example. The reason is as follows. The re-directions are done from left to right. So "2" (stderr) is associated with "1" (stdout), which at that point is still associated with the terminal. Then "1" (stdout) is re-directed to /dev/null, but that does not affect the re-directions already in effect. Reversing the order makes it work (if you think about it :) > > Joe > > > > > That will redirect all stdout and stderr to /dev/null, thus making your > > program silent. > > > > Joe > > > > > > > > All help appreciated > > > > > > > > > Thanks, > > > Matthew > > > > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > > with "unsubscribe freebsd-questions" in the body of the message > > > > > > > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > with "unsubscribe freebsd-questions" in the body of the message > > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message -- Regards Cliff To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message