0

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

Alon_T
  • 1,430
  • 4
  • 26
  • 47
  • 1
    There is no need to use `os.devnull` to redirect stdout or err. Just use `subprocess.PIPE` and ignore the output. – Martijn Pieters Jan 06 '13 at 14:08
  • Ok..will try it..does it mean to replace the line in the code to subprocess.PIPE instead of os.devnull? – Alon_T Jan 06 '13 at 14:44
  • Exactly; no need to redirect to the `/dev/null` if you can just pipe and ignore. I am not stating that that will solve your issue, just that using `/dev/null` is a shell solution, and this is Python. – Martijn Pieters Jan 06 '13 at 14:45
  • @MartijnPieters I tried it and added the result above.. :-( – Alon_T Jan 06 '13 at 15:15
  • 1
    You do *not* need to open `PIPE` as a file. Use `stdout=subprocess.PIPE`, see the documentation. :-) – Martijn Pieters Jan 06 '13 at 15:20
  • changed it to call(["/usr/sbin/atms","-k"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) and now I got the same error from the beginning "'Popen' object has no attribute '_child_created'" in > ignored __init__() got an unexpected keyword argument 'stder' – Alon_T Jan 06 '13 at 15:23

1 Answers1

0

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'
Alex L
  • 8,748
  • 5
  • 49
  • 75