2
votes

I think something is getting subtly mangeled when I attempt to execute a subprocess from a python script

I attempt to execute vlc with some (a lot) of arguments.

the instance of vlc that arises complains:

Your input can't be opened: VLC is unable to open the MRL ' -vvv rtsp://192.168.1.201:554/ch0_multicast_one --sout=#transcode{acodec=none}:duplicate{dst=rtp{sdp=rtsp://:5544/user_hash.sdp},dst=display} :no-sout-rtp-sap :no-sout-standard-sap :ttl=1 :sout-keep'. Check the log for details.

Here is the python code

pid = subprocess.Popen(["vlc "," -vvv rtsp://%s" % target_nvc.ip_address + ":554/ch0_multicast_one --sout=#transcode{acodec=none}:duplicate{dst=rtp{sdp=rtsp://:5544/user_hash.sdp},dst=display} :no-sout-rtp-sap :no-sout-standard-sap :ttl=1 :sout-keep" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)

I have examined the output of the subprocess function (using a shell), and if I copy paste that string into my cmd window, the vlc instance works fine... Is this a privilege thing?

2
What does the log say? the error message looks like it couldn't parse the options. - Tim McNamara

2 Answers

0
votes

You should use this...

pid = subprocess.Popen(["vlc", "-vvv", 
    "rtsp://%s" % target_nvc.ip_address + ":554/ch0_multicast_one", 
    "--sout=#transcode{acodec=none}:duplicate{dst=rtp{sdp=rtsp://:5544/user_hash.sdp},dst=display}", 
    ":no-sout-rtp-sap", ":no-sout-standard-sap", 
    ":ttl=1", ":sout-keep" ], stdout=subprocess.PIPE, 
    stderr=subprocess.PIPE, stdin=subprocess.PIPE)
2
votes

Since you're passing a list to subprocess.Popen, each parameter must be in its own element. So you'd want something like:

pid = subprocess.Popen([
    "vlc",
    "-vvv",
    "rtsp://%s:554/ch0_multicast_one" % target_nvc.ip_address,
    # etc
], ...)

Each parameter (that the shell would normally parse apart for you) must be in a separate list element.

You can also pass a single command line string and let the shell pull it apart:

pid = subprocess.Popen("vlc -vvv rtsp://...", shell=True, ...)

Using the first form is better for commands that have lots of arguments.