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.<br><br>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...<br><br>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.<br><br><dl class="codebox"><dd><code>import subprocess<br><br>list = 'list'<br>list_sinks =
'list-sinks'<br><br>print("### TEST 1")<br>a = subprocess.Popen('pactl '
+ list, shell=True, stdout=subprocess.PIPE)<br>res = a.communicate()<br>print(repr(res[0]))<br><br>print("###
TEST 2")<br>a = subprocess.Popen('pactl ' + list_sinks, shell=True,
stdout=subprocess.PIPE)<br>res = a.communicate()<br>print(repr(res[0]))<br><br>print("###
TEST 3")<br>a = subprocess.Popen(['pactl', list], shell=True,
stdout=subprocess.PIPE)<br>res = a.communicate()<br>print(repr(res[0]))<br><br>print("###
TEST 4")<br>a = subprocess.Popen(['pactl', list_sinks], shell=True,
stdout=subprocess.PIPE)<br>res = a.communicate()<br>print(repr(res[0]))</code></dd></dl><br>### TEST 1<br>(success... snip)<br>### TEST 2<br>No valid command
specified.<br>''<br>### TEST 3<br>No valid command specified.<br>''<br>###
TEST 4<br>No valid command specified.<br>''<br><br>Does anyone have any idea what I'm doing wrong?<br>Thanks,<br>John<br>