简体   繁体   English

在Python子进程中运行call()时出错

[英]error when running call() in Python subprocess

i'm trying to run: 我正在尝试运行:

 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

I now get 我现在得到

 coercing to Unicode: need string or buffer, int found

What does it mean? 这是什么意思?

Thanks 谢谢

open() is used for files, and expects a filename not a pipe. open()用于文件,并且期望文件名而不是管道。

Instead of .call() , you could use Popen : 可以使用Popen代替.call()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM