See this simple code:
$ python >>> from subprocess import * >>> call(['echo','Hi']) Hi 0
My problem looks simple. I don't want this <strong>0</strong> at the end of the call. Every function called by <strong>call</strong> appears with this and this messes up things for conditional tests.
if int(call(['function', 'parameter']))>10: print 'yes'
So how can I receive only
in this example?Answer1:
You want to use Popen with
communicate, as described in the docs:
>>> from subprocess import * >>> Popen(['echo', 'Hi'], stdout=PIPE).communicate() 'Hi\n'Answer2:
The value you are seeing is the return value of the
echo process. Because you are in a active interpreter this return value gets printed to the terminal. You can ignore it by assigning it to a dummy variable:
_ = call(['echo','Hi'])<hr />
Just making sure, you do know you can just write