-->

运行在Python子()调用时错误(error when running call() in Pyt

2019-11-01 08:22发布

我试图运行:

 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

这是什么意思?

谢谢

Answer 1:

open()用于文件,并期望一个文件名不是一个烟斗。

取而代之的.call()你可以使用Popen

>>> p = subprocess.Popen(['python', '-c', 'print "test"'], stdout=subprocess.PIPE)
>>> p.stdout.read()
'test\r\n'


文章来源: error when running call() in Python subprocess