Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

How can I get the output of a process run using

Passing a StringIO.StringIO object to stdout gives this error:

Traceback (most recent call last): 

File "<stdin>", line 1, in <module>   File"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/", line 444, in call return Popen(*popenargs, **kwargs).wait() 

File"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/", line 588, in __init__ errread, errwrite) = self._get_handles(stdin, stdout, stderr) 

File"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/", line 945, in _get_handles 

c2pwrite = stdout.fileno() 

AttributeError: StringIO instance has no attribute 'fileno' 


1 Answer

0 votes
by (106k points)

You can use the below-mentioned code for retrieving the output of

from subprocess import Popen, PIPE
p = Popen(['program', 'arg1'], stdin=PIPE, stdout=PIPE, stderr=PIPE) 

output, err = p.communicate(b"input data that is passed to subprocess' stdin") 

rc = p.returncode

Related questions

0 votes
4 answers
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Oct 11, 2019 in Python by Sammy (47.6k points)

Browse Categories