【问题标题】:output result of python program in both terminal and filepython程序在终端和文件中的输出结果
【发布时间】:2018-07-01 11:55:40
【问题描述】:

我试过了,但命令是一个 python 程序,有一个输入“raw_input()”

someCommand | tee someFile

当程序要求输入时输出停止

【问题讨论】:

  • 如果someCommand 需要一些输入,如果没有输入,你还期望这个命令做什么?
  • 是您没有看到输入提示的问题吗?
  • 是的,我没有看到输入提示

标签: python shell terminal output


【解决方案1】:

有几种方法可以解决这个问题。 raw_input() 读取标准输入 (stdin),可以从管道、文件甚至其他进程重定向:

使用管道:

echo "some text" | someCommand | tee someFile

来自文件:

someCommand < inputfile | tee someFile

来自另一个程序:

someCommand < <(anotherprog) | tee someFile

在每种情况下,换行符都应该终止数据。

或者,可以更改 python 程序,使其写入输出文件以及控制台,但我猜这不是一个选项。

【讨论】:

    猜你喜欢
    • 2014-04-10
    • 2018-10-11
    • 1970-01-01
    • 2011-06-26
    • 2021-08-16
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多