如何打印所有已打印并可在终端上看到的内容

How to print everything that is printed and can be seen on terminal

我想打印 GROMACS 5.1.2 的所有输出。

我知道如何使用 >< 进行 std in 和 out,也试过 2>&1 一起打印错误和输出,也单独试过,它仍然无法打印一切,尤其是最后一些有用的提示,它告诉我问题出在哪里,我需要这些信息。

我认为这不会被保存,因为它来自不同的代码,主程序执行一个子程序,然后崩溃,我只在屏幕上得到报告。我会在输出中显示出了什么问题,以及那是什么,但在屏幕上我有更多信息。

如果有人知道我该怎么做,我将不胜感激。

我也不是完全的菜鸟,但如果你能在你的解释中明确,那将不胜感激。

例如,如果您想使用来自 RCBS 蛋白质数据库的 3mlj.pdb 尝试 gmx pdb2gmx 命令,我将在屏幕上阅读:

Fatal error:
Residue 'CU' not found in residue topology database

但在标准输出中我只会读取:

This chain does not appear to contain a recognized chain molecule.

对我来说,CU 是非常重要的信息,这只是一个例子。

我在这里分享我的操作系统:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty

也试过这个,结果完全一样:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.10
Release:    15.10
Codename:   wily

我想要 运行 用于批处理文件的 bash 脚本:

#$ -S /bin/bash
for infile in *.pdb
do
    gmx pdb2gmx -f $infile -o ${infile/pdb/gro} -water spce -ff oplsaa \
        -p ${infile/pdb/top} -i ${infile/pdb/itp} 2>&1 > ${infile/pdb/err}
done

您必须以正确的顺序(从左到右)执行 I/O 重定向。

你有:

gmx pdb2gmx …  -i ${infile/pdb/itp} 2>&1 > ${infile/pdb/err}

这会将标准错误发送到标准输出当前所在的位置(终端),然后将标准输出(但不是标准错误)发送到文件。

你需要:

gmx pdb2gmx …  -i ${infile/pdb/itp} > ${infile/pdb/err} 2>&1

这会将标准输出发送到一个文件,然后将标准错误发送到同一个地方。请注意,在两个系统中,仍然使用两个单独的文件描述符(1 或标准输出,以及 2 或标准错误);唯一的问题是文件描述符连接到哪个文件。

如果您正在传输数据,则在处理其他 I/O 重定向之前设置管道,否则,每个命令的 I/O 重定向将从左到右处理。

另见 How to pipe stderr and not stdout, and Bash I/O Redirections