Save “screen” (program) output to a file

2019-01-12 20:01发布

I need to save the whole output of screen to a file to check later all the content.
The reason is that I'm dumping a flash memory trough serial port, using screen to interface with it.
I would like to save it to a file to check memory structure.

I've tried :

$: screen /dev/ttyUSB0 115200 >> foo.txt
$: screen /dev/ttyUSB0 115200 | tee foo.txt

and I've also tried to use bufferfile from screen, but I don't understand how to use it.

Is there an easy way?

9条回答
何必那么认真
2楼-- · 2019-01-12 20:16

The 'script' command under Unix should do the trick. Just run it at the start of your new console and you should be good.

查看更多
叼着烟拽天下
3楼-- · 2019-01-12 20:17

The following command works for screen version 4.06.02

screen -L -Logfile Log_file_name_of_your_choice command_to_be_executed

From man page of the screen:

-Logfile file : By default logfile name is "screenlog.0". 
                You can set new logfile name with the "-Logfile" option.

You can check the existing version of screen using screen -version. You can download and install latest screen version from https://www.gnu.org/software/screen/.

查看更多
小情绪 Triste *
4楼-- · 2019-01-12 20:18

Here's a trick: wrap it in sh -c!

screen sh -c './some-script 2>&1 | tee mylog.log'

Where 2>&1 redirects stderr to stdout so tee can catch and log error messages.

查看更多
\"骚年 ilove
5楼-- · 2019-01-12 20:22

You can also use Control-a + H to save loggings into screenlog.n file. One more Control-a + H to turn off.

C-a H: Begins/ends logging of the current window to the file "screenlog.n".

查看更多
倾城 Initia
6楼-- · 2019-01-12 20:22

Ctrl+A then Shift+H works for me. You can view the file screenlog.0 while the program is still running.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-01-12 20:35

There is a command line option for logging. The output is saved to screenlog.n file, where n is a number of the screen. From man pages of screen:

‘-L’ Tell screen to turn on automatic output logging for the windows.

查看更多
登录 后发表回答