【发布时间】:2020-11-30 21:13:07
【问题描述】:
当我执行下面的程序时,它会正确列出文件。
import subprocess
foo = subprocess.run("ls /home/my_home",
shell=True,
executable="/bin/bash",
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
my_std_out = foo.stdout.decode("utf-8")
但是当执行下面的程序时,stdout里面什么都没有。
import subprocess
foo = subprocess.Popen(["ls /home/my_home"],
shell=True,
executable="/bin/bash",
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
my_std_out = foo.stdout.read().decode("utf-8")
我想知道我的第二部分程序有什么问题吗?
提前谢谢你!
【问题讨论】:
-
您的代码原样无效,因为以下行:executable=/bin/bash。你打算把它放在引号里吗?
标签: python python-3.x shell subprocess