【问题标题】:Print command line output into a text file in Linux (Ubuntu)在 Linux (Ubuntu) 中将命令行输出打印到文本文件中
【发布时间】:2013-10-08 05:53:13
【问题描述】:

我在 Linux (Ubuntu) 中有一个 C++ 程序,它在命令终端中打印很长的输出。

如何通过 Linux 命令将命令终端的输出直接复制到 .txt 文件中?

【问题讨论】:

    标签: c++ linux command-line


    【解决方案1】:

    您的 shell 通过输出重定向为您执行此操作:

    $ ./a.out > theoutput.txt
    

    【讨论】:

    • 执行此命令时出现错误:bash: ./a.out: No such file or directory
    • @BlueBit:替换自己程序的实际文件名...(或者只是将所有程序称为 a.out,就像您的本意那样 :-))
    【解决方案2】:

    一般你输入;

    command > file.txt
    

    大于号 > 将标准输出重定向到文件。

    【讨论】:

    • 没错。您将输出“管道”到文件。
    • 实际上管道将用于将标准输出发送到另一个进程的标准输入,即“command | command2”。不是一回事。
    • 一个改进是分别保留stdoutstderrcommand 1>outFile 2>errFile
    猜你喜欢
    • 2011-04-03
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多