0

I am trying to run a big script that prompts for answers along the way. I want to run it in verbose mode and thus there will be significant output and I'd like to capture it. Therefore I'd like to run it in a way that allows me to answer the questions as well as sending the output to a file.

Can this be done ?

Thanks.

Mike

0

1 Answer 1

1

While answering you are giving input via file descriptor 0 i.e. STDIN and the program is showing output on file descriptor 1 i.e. STDOUT. As you can see these two are wowking on different file descriptors and manipulating one should not hamper the operation of other.

Note that there is also file descriptor 2 i.e. STDERR normally used for showing error messages.

In you case run the script as:

./myscript.sh >~/script.out

Now you can provide input answers to the questions of the script via STDIN and the output of the program will be saved in ~/script.out.

You can save the error also e.g. in another file:

./myscript.sh >~/script.out 2>~/script.err

The STDOUT will be saved in ~/script.out and the STDERR will be saved in ~/script.err.

You can save the output and error both in the same file:

./myscript.sh >~/script.all 2>&1

Now ~/script.all will contain the outputs and error messages (if any) from myscript.sh.

Not the answer you're looking for? Browse other questions tagged .