小编use*_*678的帖子

如何从子进程 python 2.7 和 Apache 读取实时输出

我有一个 Apache Web 服务器,我制作了一个 python 脚本来运行命令。我正在运行的命令正在启动一个 ROS 启动文件,该文件无限期地工作。我想实时读取子流程的输出并将其显示在页面中。到目前为止,我的代码只能在终止进程后才能打印输出。我已经尝试了网络上的各种解决方案,但似乎都不起作用

command = "roslaunch package test.launch"
proc = subprocess.Popen(
   command,
   stdout=subprocess.PIPE,
   stderr=subprocess.STDOUT,
   env=env,
   shell=True,
   bufsize=1,
)
print "Content-type:text/html\r\n\r\n"
for line in iter(proc.stdout.readline, ''):
   strLine = str(line).rstrip()
   print(">>> " + strLine)
   print("<br/>")
Run Code Online (Sandbox Code Playgroud)

apache subprocess pipe python-2.7 ros

5
推荐指数
1
解决办法
1459
查看次数

标签 统计

apache ×1

pipe ×1

python-2.7 ×1

ros ×1

subprocess ×1