piping stderr & stdout to /dev/null

Hi,

I've never worked with stderr and stdout before. I have an application that sends an obscene number of messages to the Console log, so implemented the following shell script to launch it in future:

/Volumes/Storage/Shared/Games/UrbanTerror/ioUrbanTerror.app/Contents/MacOS/ioUrb anTerror.ub >> 2&>1 /dev/null

No further entries appeared in the Console so I thought I was sorted, but then I discovered two files in the root of my Home directory called 1 and 2 respectively, and these contained the log outputs. I thought /dev/null was supposed to be the computer equivalent of "oblivion," so have I implemented the shell script incorrectly?

Also, can someone further modify my script so that stdout goes to /dev/null and stderr goes to a log file in a location of my choosing?

Many thanks,

S.

MacBook Pro MB470LL/A, 4GB RAM, Mac OS X (10.6.5), ; Mac Pro 2010 10.6.5; iPhone 3GS 16GB iOS4.0.2; AEBS MA053LL/A

Posted on Feb 3, 2011 1:04 AM

Reply
3 replies

Feb 3, 2011 5:25 AM in response to SiRGadaBout

No further entries appeared in the Console so I thought I was sorted, but then I discovered two files in the root of my Home directory called 1 and 2 respectively, and these contained the log outputs. I thought /dev/null was supposed to be the computer equivalent of "oblivion," so have I implemented the shell script incorrectly?

The >> should have been next to /dev/null, the & was in the wrong place, and the 2>&1 should follow the >>/dev/null. Understanding the 2>&1 behavior is a bit tricky.

/Volumes/Storage/Shared/Games/UrbanTerror/ioUrbanTerror.app/Contents/MacOS/ioUrbanTerror.ub >/dev/null 2>&1

You could have also just redirected stdout and stderr separately to /dev/null

/Volumes/Storage/Shared/Games/UrbanTerror/ioUrbanTerror.app/Contents/MacOS/ioUrbanTerror.ub >/dev/null 2>/dev/null

Also, can someone further modify my script so that stdout goes to /dev/null and stderr goes to a log file in a location of my choosing?


/Volumes/Storage/Shared/Games/UrbanTerror/ioUrbanTerror.app/Contents/MacOS/ioUrbanTerror.ub >/dev/null 2>/location/of/your/choosing/file.log

This will overwrite file.log every time you invoke the script. Or if you want to append to the file you can use:

/Volumes/Storage/Shared/Games/UrbanTerror/ioUrbanTerror.app/Contents/MacOS/ioUrbanTerror.ub >/dev/null 2>>/location/of/your/choosing/file.log

Or if you want to use dated log files for each running of the script:

/Volumes/Storage/Shared/Games/UrbanTerror/ioUrbanTerror.app/Contents/MacOS/ioUrbanTerror.ub >/dev/null 2>/location/of/your/choosing/file.$(date +%Y%m%d%H%M).log


Message was edited by: BobHarris

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

piping stderr & stdout to /dev/null

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.