简体   繁体   English

python popen可以捕获子流程的子流程的交互式输出吗?

[英]Can python popen capture interactive output of a subprocess of a subprocess

We have an app named app.exe which in turn is a wrapper for a java.exe for the installanywhere launcher. 我们有一个名为app.exe的应用程序,它反过来又是installanywhere启动器的java.exe的包装。 Suppose we have a python script a.py which calls app.exe which then spawns the java.exe process, how do we capture the interactive outputs and inputs between a.py and java.exe 假设我们有一个python脚本a.py,它调用了app.exe,然后生成了java.exe进程,我们如何捕获a.py和java.exe之间的交互输出和输入

Can Popen do that ? Popen可以做到吗? Are there simple examples we could read more to follow ? 有没有简单的例子我们可以阅读更多内容? Can pexpect be used in this scenario too ? 可以在这种情况下使用pexpect吗?

Thanks 谢谢

That's possible if your a.exe redirects its own stdin to java.exe stdin and java.exe stdout to its own stdout . 如果您的a.exe将其自己的stdin重定向到java.exe stdin并将java.exe stdout重定向到其自己的stdout,则有可能

Have a look at subprocess.Popen . 看看subprocess.Popen There are 2 optional arguments: stdin controlling subproces's standard input and stdout , which controls subproces's standard output. 有2个可选参数: stdin控制子过程的标准输入和stdout ,控制子过程的标准输出。

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

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