从python/子进程调用另一个进程需要访问shell
我正在使用 Popen
从 python 调用 C/C++ 程序,python 代码应该观察子进程的行为并为他自己的工作收集一些数据。
问题是 C 代码已经使用管道来调用一些 shell 命令 - 所以在我从 python 执行之后,C 程序无法执行 bash shell 命令。
有没有办法从 Popen
调用来指定子进程应该在 shell 中执行自己的管道命令???
我尝试使用 shell=True,但没有帮助!
I'm calling a C/C++ program from python with Popen
, python code should observe behavior of child process and collect some data for his own work.
Problem is that C code already uses pipes for calling some shell commands - so after my execution from python, C program cannot execute bash shell command.
Is there any way in calling from Popen
to specify that, child process should execute his own pipe command in shell???
I tried with shell=True, but doesn't help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的描述来看,您似乎正在使用 Popen 执行命令行,其中 Popen 调用 shell。
您应该让 Popen 直接调用您的程序,如下所示:
From your description, it seems that you are using Popen to execute a command line, which has Popen call a shell.
You should instead have Popen call your program directly, like this:
最好的方法可能是使用 TCP 连接到本地主机。如果您使用的是 *nix,您可以通过打开一个临时文件并从主机应用程序轮询它来完成此操作。
The best way is probably to use a TCP connection to localhost. If you are using a *nix, you can probably do it by opening a temporary file and polling it from the host application.