0
>>> import subprocess >>> subprocess.Popen("pwd") <subprocess.Popen object at 0xa7692cc> >>> subprocess.call(["ls", "-l"]) 0 

I have tried the above command in Python interactive shell and expect to see the output inside the shell environment. However, it ends up with just some return values.

What should I do in order to let the return results printed inside the shell?

2 Answers 2

4

It'd help to read the documentation first.

p = subprocess.Popen('pwd', stdout = subprocess.PIPE) p.communicate() # returns (stdout, None) 
Sign up to request clarification or add additional context in comments.

Comments

1

Cat Plus Plus is right, however, if you prefer the call function, you can also do this like so:

import subprocess import sys subprocess.call('pwd', stdout=sys.stdout) # outputs results of `pwd` to stdout 

2 Comments

import subprocess, sys subprocess.call('pwd', stdout=sys.stdout) Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/lib/python2.6/subprocess.py", line 480, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.6/subprocess.py", line 626, in __init__ errread, errwrite) = self._get_handles(stdin, stdout, stderr) File "/usr/lib/python2.6/subprocess.py", line 983, in _get_handles c2pwrite = stdout.fileno() AttributeError: PseudoFileOut instance has no attribute 'fileno'
What do you mean? It seems like I cannot run the solution provided by Adam.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.