当linuxcat调用via时,我有一个意外的行为子流程.Popen(). 在
Python脚本的结构如下:
import os, subprocess
def _degrade_child_rights(user_uid, user_gid):
def result():
os.setgid(user_gid)
os.setegid(user_gid)
os.setuid(user_uid)
os.seteuid(user_uid)
return result
child = subprocess.Popen("cat /home/myuser/myfolder/screenlog.0",
preexec_fn=_degrade_child_rights(0, 0), shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
当我用ps aux | grep cat检查执行的shell命令时,它显示python成功地运行了shell命令。在
^{pr2}$然而,cat命令永远不会结束。在
我还将cat$file命令外包给bash脚本。然后bash执行我的cat调用,但也阻塞。在
当我手动执行cat$file时,它的运行与预期的一样,因此在文件末尾不存在的EOF也是不可能的。在
我认为,Popen添加的'/bin/sh-c'在某种程度上扰乱了cat$file的正确执行。在
我能阻止吗?在
您可能需要尝试Popen对象的通信方法:
在^{} python doc 中有更多信息
相关问题 更多 >
编程相关推荐