irick@ecn.purdue.edu (GarBear Irick) (05/02/90)
In article <1605@dinl.mmc.UUCP> noren@dinl.UUCP (Charles Noren) writes: >What I want to do is: > > ls *.o | some-util > >so that if there is no *.o files, it will not be reported. >In other words, can I close only stderr (or redirect it to >/dev/null) while keeping stdin and stdout unaffected? Call me silly, but this should work... ( ls *.o > /tmp/lsfile$$ ) >& /dev/null;cat /tmp/lsfile$$ | some-util I can't think of a one-statement equivalent that will do it off of the top of my head. If anyone comes up with a better solution, PLEASE post it... Just don't exceed the 4000 degrees F limit on my anti-flame unit. Gary A. Irick, irick@en.ecn.purdue.edu Purdue University Engineering Computer Network
jik@athena.mit.edu (Jonathan I. Kamens) (05/02/90)
In article <1605@dinl.mmc.UUCP>, noren@dinl.uucp (Charles Noren) writes: |> What I want to do is: |> |> ls *.o | some-util |> |> so that if there is no *.o files, it will not be reported. |> In other words, can I close only stderr (or redirect it to |> /dev/null) while keeping stdin and stdout unaffected? May I humbly suggest that you RTFM before posting a question like this to the net? I'm fairly certain that the man page sh(1) talks about using the num>file syntax to redirect a specific file descriptor somewhere. In this particular case, you might try: ls *.o 2>/dev/null | some-util Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710
noren@dinl.uucp (Charles Noren) (05/02/90)
In article <1990May2.042244.13723@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <1605@dinl.mmc.UUCP>, noren@dinl.uucp (Charles Noren) writes: ...a simple RFTM type question (and a frequently asked question no less). > May I humbly suggest that you RTFM before posting a question like this >to the net? I'm fairly certain that the man page sh(1) talks about ...yes it does, and I stared at it for an hour and tried it out and it didn't work until I realized I was in csh. Sorry to waste the net bandwidth on this one. I deserved the flame on this question. Thanks for all the kind e-mail responses also. -- Chuck Noren NET: ncar!dinl!noren US-MAIL: Martin Marietta I&CS, MS XL8058, P.O. Box 1260, Denver, CO 80201-1260 Phone: (303) 971-7930
bob@wyse.wyse.com (Bob McGowen Wyse Technology Training) (05/03/90)
In article <1990May2.000457.9488@ecn.purdue.edu> irick@ecn.purdue.edu (GarBear Irick) writes: >In article <1605@dinl.mmc.UUCP> noren@dinl.UUCP (Charles Noren) writes: >>What I want to do is: >> >> ls *.o | some-util >> >>so that if there is no *.o files, it will not be reported. >>In other words, can I close only stderr (or redirect it to >>/dev/null) while keeping stdin and stdout unaffected? yes > >Call me silly, but this should work... ---deleted solution--- >Gary A. Irick, irick@en.ecn.purdue.edu >Purdue University Engineering Computer Network With the Bourne shell, if there is no match for the wild card the argument is passed to the command as is and the ls generates an error message on standard error. The following should do what you want: ls *.o 2>/dev/null | some-util On my system (XENIX 2.3.2), the 2>/dev/null must follow immediately after the ls. If it follows "some-util", the ls error is still printed to the screen. Note that csh deals with wildcards somewhat differently than sh when there is no match for the pattern. Errors are generated by csh itself rather than the utility and I am not sure how you would deal with it. Bob McGowan (standard disclaimer, these are my own ...) Customer Education, Wyse Technology, San Jose, CA ..!uunet!wyse!bob bob@wyse.com
guy@auspex.auspex.com (Guy Harris) (05/05/90)
>The following should do what you want: > > ls *.o 2>/dev/null | some-util And may also do a bunch of stuff that he *doesn't* want, namely throwing out any *other* error messages that might occur (like "I/O error" - yes, I *have* had that happen, with a disk that occasionally went offline; the appearance of "I/O error" was a signal that it was time to run off and reset the disk - or "Connection timed out").