Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a c++ code got started by a shell script. The shell script has the following line to start the c++ code /home/user/test_client/a.out Now i want to capture the output of this code in a file called message.log What is the right way to do this ? I have tried /home/user/test_client/a.out >> message.log It doesn't work. Am I doing anything wrong here ?

share|improve this question
"It doesn't work" is not a helpful description of the problem. Did you get an error? – David Schwartz Jun 22 '12 at 3:07
@David Schwartz: Sorry about that. I am not getting error. The message.log file is created and its empty. and the a,out is running as well.. – Deepak Jun 22 '12 at 3:11
up vote 4 down vote accepted

Try a.out >> message.log 2>&1

That will also redirect stderr, which is probably where the messages are going.

share|improve this answer
Okay i will try that.. Actually the log file i am creating is inside /var/log/message.log so is there any problem with that ? – Deepak Jun 22 '12 at 3:04
Are you running it as root? Typically users cant write to /var/log/message.log. Try writting it to your home directory instead. – Grant Jun 22 '12 at 3:11
I got it sorted.. There is no output from the a.out at this stage.. It will output only in case of some errors. So thanks for that!! 2>&1 helped me in this case... – Deepak Jun 22 '12 at 3:17

Please use the syslog API for write to /var/log/messages

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.