python - 如何使用 popen 对输出进行管道传输?

标签 python popen

我想使用popen管道输出我的文件,我该怎么做?

测试.py:

while True:
  print"hello"

a.py :

import os  
os.popen('python test.py')

我想使用 os.popen 管道输出。 我怎样才能做同样的事情?

最佳答案

首先,os.popen() 已弃用,请改用 subprocess 模块。

你可以这样使用它:

from subprocess import Popen, PIPE

output = Popen(['command-to-run', 'some-argument'], stdout=PIPE)
print output.stdout.read()

关于python - 如何使用 popen 对输出进行管道传输?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4537259/

相关文章:

Python逻辑错误?

python - 创建新实例时,python中的类变量是否会再次声明?

python - 描述一下你为 Python/Django 开发定制的 Vim 编辑器?

python - 在进程运行时读取进程的输出

python - Pandas - 使用变换对组进行操作

python - 抓取 Google Scholar 时防止 503 错误

c - fgets 为 popen 返回的 FILE 返回错误

php - 如何同时(非阻塞)运行 2 个 PHP 脚本来监视 popen 命令?

python - 检测进程中止

python - 在 Windows 上从 Python 脚本使用 g++ 编译 C++ 代码