如何使用脚本创建终端会话的打字稿?

时间:2015-05-18 04:54:27

标签: shell gcc terminal

我应该编译并运行我的文件,并在脚本中用脚本记录它。但是当我尝试它时,我在文件中得到了意想不到的结果。我做错了吗?

$ script
Script started, file is typescript
developer@developer-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ gcc -Wall -O4 -ansi -pedantic miniShell.c
developer@developer-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ exit
exit
Script done, file is typescript
developer@developer-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ more typescript 
Script started on Mon 18 May 2015 06:38:38 CEST
developer@de
-ansi -pedantic miniShell.cp/kth/os/smallshell/oslab$ gcc -Wall -O4  
developer@de
veloper-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ exit
exit

Script done on Mon 18 May 2015 06:38:58 CEST
developer@developer-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ 

1 个答案:

答案 0 :(得分:1)

script记录发送到您终端的所有字符。这包括各种终端控制序列(如光标移动,颜色等)。

默认情况下,less(和其他页面)对这些控制字符不起作用。使用-R option of less允许程序呈现最初发送的文件。存在一些限制,因为即使这样也假定文件不是在全屏模式下生成的。要处理 ,您最好的选择是将文件缓慢cat发送到与生成文件的相同大小的终端。为此,我使用了一个程序slowcat。其他人使用-t选项script来记录时间信息(但script的所有版本都没有 - 基本上是Linux特定的。)

或者,您可以使用程序或脚本删除这些控制序列,并获得与less -R显示的内容相当的内容(没有视频突出显示和颜色)。有关如何执行此操作的一些讨论,请参阅 Can I programmatically “burn in” ANSI control codes to a file using unix utils?