tags:

views:

47

answers:

4

I am running a task on the CLI, which prompts me for a yes/no.

After selecting a choice, a vast amount of info scrolls on the screen - including several errors. I want to pipe the output to a file so I can see the errors - but a simple '>' is not working since the command expects a keyboar input.

i am running on Ubuntu 9.1

A: 

Use 2> rather than just >.

Delan Azabani
A: 

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

GregMeno
A: 
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
John Kugelman
Redirecting both stdout and stderr to a file means he wont see the actual prompt. I can't see how he would be any better off than the situation he describes in his question.
Epcylon
A: 
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.

Epcylon
I think you mean `echo yes | command` rather than `command < \`echo yes\``. (There's also the `yes` command which might be useful.)
Jukka Matilainen
You're right. I started out thinking he could put his input in a file, and changed my mind to simply using echo instead, but forgot to change the command-line to match. Fixed it now.
Epcylon