【发布时间】:2013-01-06 13:52:09
【问题描述】:
我正在尝试运行:
try:
with open(subprocess.PIPE, 'w') as pipe:
call(["/usr/sbin/atms","-k"], stdout=pipe, stderr=pipe)
call(["/usr/sbin/atms","/usr/sbin/atms.conf"],stdout=pipe,stder=pipe)
except Exception, e:
print e
我现在明白了
coercing to Unicode: need string or buffer, int found
什么意思?
谢谢
【问题讨论】:
-
不需要使用
os.devnull来重定向stdout或err。只需使用subprocess.PIPE并忽略输出。 -
好的..会试试..是不是要把代码中的那一行替换成subprocess.PIPE而不是os.devnull?
-
完全正确;如果您可以通过管道忽略,则无需重定向到
/dev/null。我并不是说这会解决你的问题,只是说使用/dev/null是一个 shell 解决方案,这就是 Python。 -
@MartijnPieters 我试过了并在上面添加了结果.. :-(
-
您确实不需要需要将
PIPE作为文件打开。使用stdout=subprocess.PIPE,请参阅文档。 :-)