open()
is used for files, and expects a filename not a pipe.
Instead of .call()
, you could use Popen
:
>>> p = subprocess.Popen(['python', '-c', 'print "test"'], stdout=subprocess.PIPE)
>>> p.stdout.read()
'test\r\n'
题
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.
Instead of .call()
, you could use Popen
:
>>> p = subprocess.Popen(['python', '-c', 'print "test"'], stdout=subprocess.PIPE)
>>> p.stdout.read()
'test\r\n'