简体   繁体   English

python程序在终端和文件中的输出结果

[英]output result of python program in both terminal and file

i tried this but the command is a python program that has an input "raw_input()" 我试过了,但命令是一个具有输入“ raw_input()”的python程序

someCommand | tee someFile

the output stops at the moment when the program asks for the input 当程序要求输入时,输出停止

There are several ways around this. 有几种解决方法。 raw_input() reads standard input ( stdin ) which can be redirected from a pipe, a file, or even another process: raw_input()读取标准输入stdin ),可以从管道,文件甚至其他进程重定向:

Using a pipe: 使用管道:

echo "some text" | someCommand | tee someFile

From a file: 从文件中:

someCommand < inputfile | tee someFile

From another program: 从另一个程序:

someCommand < <(anotherprog) | tee someFile

In each case a newline should terminate the data. 在每种情况下,换行符都应终止数据。

Alternatively the python program could be altered so that it writes to an output file as well as the console, but I'm guessing that's not an option. 或者,可以更改python程序,以便将其写入输出文件以及控制台,但是我猜这不是一个选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM