Reputation: 17016
I am running a task on the CLI, which prompts me for a yes/no input.
After selecting a choice, a large amount of info scrolls by on the screen - including several errors. I want to pipe this output to a file so I can see the errors. A simple '>' is not working since the command expects keyboard input.
I am running on Ubuntu 9.1.
Upvotes: 22
Views: 83403
Reputation: 362187
command &> output.txt
You can use &>
to redirect both stdout and stderr to a file. This is shorthand for command > output.txt 2>&1
where the 2>&1
means "send stderr to the same place as stdout" (stdout is file descriptor 1, stderr is 2).
For interactive commands I usually don't bother saving to a file if I can use less
and read the results right away:
command 2>&1 | less
Upvotes: 50
Reputation: 165
you can use 2> option to send errors to the file.
example:
command 2> error.txt
(use of option 2>) --- see if their would be any error while the execution of the command it will send it to the file error.txt.
Upvotes: 1
Reputation: 4737
echo yes | command > output.txt
Depending on how the command reads it's input (some programs discard whatever was on stdin before it displays it's prompt, but most don't), this should work on any sane CLI-environment.
Upvotes: 4
Reputation: 31
If the program was written by a sane person what you probably want is the stderr not the stdout. You would achieve this by using something like
foo 2> errors.txt
Upvotes: 1