Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 started a program written using Node.js and started it using launch pipe into logfile and send it to background.

Half way running the program exited w/o any error both on the console nor the log, I even checked the /var/log/message and no way I could figure out what's wrong with the program.

Are there any better way to able to capture the error/messages that causes the exit?

The current execution bash script is following:

./run_all_with_logs >> logs/my.log &
share|improve this question
up vote 3 down vote accepted

Let's enhance P.T.:s answer just a little.

The basic form sends all normal output to the log file.

./run_all_with_logs >> logs/my.log &

If we redirect the errors we can log both the errors and the normal printouts.

./run_all_with_logs 2>&1 >> logs/my.log &

If we then executes the command in a subshell we can print the exit code as well.

(./run_all_with_logs ; echo "Final Exit Code: $?" ) 2>&1  >> logs/my.log &
share|improve this answer
Yeah, including stderr is a very important addition. – P.T. Sep 26 '11 at 17:11
Thanks Johan, you made the best suggestion. – d4v1dv00 Sep 27 '11 at 2:34

The exit code should tell you if the process was killed by an external signal or exited with a (hopefully useful) internal exit code on its own.

You can expand your command-line a bit to include the exit code (see other questions for decoding this exit code):

(./run_all_with_logs ; echo "Final Exit Code: $?" ) >> logs/my.log &

You could make this a bit fancier (decoding exit status, etc).

share|improve this answer
Add the magical 2>&1 so you log the errors as well, and your answer will be even better. – Johan Sep 26 '11 at 14:12
@Johan: better keep the changes minimal with respect to the OP's command line or you would confuse everyone. – Stéphane Gimenez Sep 26 '11 at 14:30

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.