Fighting with subprocess.Popen

Mr.John phiporiphic at gmail.com
Sun Feb 14 15:23:41 EST 2010


I'm using Python 2.6.2 as packaged with Fedora 12. I'm trying to use
subprocess.Popen() to call /usr/bin/pactl, a simple PulseAudio command
parser.

I'm having a hard time, because it only works part of the time. If pactl
gets a blank or invalid command, it says "No valid command specified.", and
this is what prints to stderr most of the time. I can get the result of
"pactl list", but anything else I try returns "No valid command specified."
So, pactl is getting called, but my args are disappearing somewhere. But not
every time...

Below is a test case that demonstrates this. Tests 1 & 2 concatenate the
command and the argument, Tests 3 & 4 mimic the python docs and use the form
Popen(["mycmd", "myarg"], ...), which never seems to work.

import subprocess

list = 'list'
list_sinks = 'list-sinks'

print("### TEST 1")
a = subprocess.Popen('pactl ' + list, shell=True, stdout=subprocess.PIPE)
res = a.communicate()
print(repr(res[0]))

print("### TEST 2")
a = subprocess.Popen('pactl ' + list_sinks, shell=True,
stdout=subprocess.PIPE)
res = a.communicate()
print(repr(res[0]))

print("### TEST 3")
a = subprocess.Popen(['pactl', list], shell=True, stdout=subprocess.PIPE)
res = a.communicate()
print(repr(res[0]))

print("### TEST 4")
a = subprocess.Popen(['pactl', list_sinks], shell=True,
stdout=subprocess.PIPE)
res = a.communicate()
print(repr(res[0]))
### TEST 1
(success... snip)
### TEST 2
No valid command specified.
''
### TEST 3
No valid command specified.
''
### TEST 4
No valid command specified.
''

Does anyone have any idea what I'm doing wrong?
Thanks,
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100214/fb7ed8ad/attachment.html>


More information about the Python-list mailing list