Linux (Bash): redirect all output to file

I am trying to redirect all output from the command line to a file. I am using Bash. Some of the results are directed to a file, but some are still displayed in the terminal and are not saved in the file.

Similar symptoms are described here:

Redirect all output to file

However, I tried the proposed solution (capture stderr) without success:

<cmd> <args> > stdout.txt 2> stderr.txt 

The stderr.txt file is created but empty.

A possible hint is that the command line program is a client interacting with the server on the same computer. It is possible that some of the results come from the server. .

Is there a way to capture all the output from the terminal, regardless of its origin?

EDIT:

I confirmed that the missing output is generated by the server. Running the command in a separate terminal causes some output in both terminals, I can transfer all the output from the command line to a file. This causes problems with capturing server output, but that's another matter.

+49
linux bash stdout stderr
May 30 '13 at 17:03
source share
6 answers

If the server is running on the same terminal, then this is the stderr server, which is supposedly written to the terminal and which you do not capture.

The best way to capture everything would be to run:

 script output.txt 

before starting either the server or the client. This will launch a new shell with all terminal pins redirected from output.txt, as well as with the terminal. Then start the server from this new shell, and then from the client. Everything that you see on the screen (both your input and the output of everything that is written to the terminal from this shell) will be written to the file.

When you're done, type "exit" to exit the shell executed by the script command.

+44
May 30 '13 at 17:20
source share
— -

you can use this syntax to redirect all output stderr and stdout to stdout.txt

 <cmd> <args> > allout.txt 2>&1 
+72
May 30 '13 at 17:42
source share

Although not POSIX, bash 4 has the &> operator:

command &> alloutput.txt

+20
Apr 23 '16 at 7:10
source share

You can run a subshell and redirect all output, leaving the process in the background:

 ( ./script.sh blah > ~/log/blah.log 2>&1 ) & echo $! > ~/pids/blah.pid 
+3
Dec 16 '15 at 17:39
source share

The correct answer is here: http://scratching.psybermonkey.net/2011/02/ssh-how-to-pipe-output-from-local-to.html

 your_command | ssh username@server "cat > filename.txt" 
+1
Aug 01 '14 at 2:56
source share

I am having problems with the program crash * cough with PHP cough * When it encounters a shell, it is started in messages about the reason for the crash, Segmentation fault (core dumped)

To prevent this output from being registered, the command can be run in a subshell that will capture and direct this output:

 sh -c 'your_command' > your_stdout.log 2> your_stderr.err # or sh -c 'your_command' > your_stdout.log 2>&1 
0
Sep 01 '15 at 22:46
source share



All Articles