![](/img/trans.png)
[英]How to capture Python interpreter's and/or CMD.EXE's output from a Python script?
[英]In Windows' cmd.exe shell, how can I pipe the output of a Perl script to a Python script?
假设我有一个perl
程序示例,可以使用以下命令从CMD(Windows 7)运行:
perl hello.pl
输出:
Hello World!
我可以使用以下命令将其放置在文件中:
perl hello.pl > output.txt
但是,我想做的是将它提供给另一个应用程序,为此,我需要将其提供给Python应用程序。 我使用以下语法为我的Python应用程序提供参数:
python python.py Arg1 Arg2 Arg3
假设我的Perl程序仅给出一个参数,一旦用完该参数,是否可以运行Python应用程序?
使您的python程序从sys.stdin
读取perl程序的输出,并将perl程序的stdout传递给它:
perl hello.pl | python python.py Arg1 Arg2 Arg3
我测试了从一个python程序到另一个python的运行情况,而在第二个python程序中却做了:
import sys
inp = sys.stdin.readline()
print(inp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.