1

How do I log the output(regular or error) of a Unix program into a file?

0

2 Answers 2

8

start it with

./program > file.log 2>&1
this will redirect stdout and stderr to file.log

Sign up to request clarification or add additional context in comments.

Comments

1

Redirection like the above answer is very standard, but sometimes you really want to capture everything in a session. For that you can use the 'script' command.

$ script /path/to/output_file
[starts a subshell]
$ ./program
$ exit
$ cat /path/to/output_file

The advantage of script is you don't need to worry about shell semantics and knowing which shell you're running etc.. The disadvantage is that it really does capture everything that makes it to your terminal, including control codes, delete keys, etc...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.