Subprocess call bash script
<p>Im trying to call a python class which contains a subprocess call for a bashscript.</p>

<pre><code>def downloadURL(self,address):

        call(['bash youtube2mp3_2.sh', str(address)],shell=True)
</code></pre>

<p>This is the bash script:</p>

<pre><code>#!/bin/bash 
# Script for grabbing the audio of youtube videos as mp3. 
address=$1
user_name=$2 # todo

path_music=/home/pi/music_loaded

echo  Address : $address

#title=$(youtube-dl --get-title $address)
youtube-dl --no-playlist  -x --audio-format mp3 -o $path_music/'%(title)s.%          (ext)s' $address
echo ----Download finshed----
</code></pre>

<p>When calling the method downloadURl I pass a static youtube link. Printing him in the python method returns it correctly.</p>

<p>But the echo in the script return "" in consonsole. So I think the Argument which I`am trying to pass is not passed to the script. </p>

<p>Does anyone have a Idea?</p>

<p>either you pass the arguments as a string</p>

<pre><code>def downloadURL(self,address):
        call('bash youtube2mp3_2.sh '+address)
</code></pre>

<p>or as a list</p>

<pre><code>def downloadURL(self,address):
        call(['bash','youtube2mp3_2.sh',address])
</code></pre>

<p>both work, but the latter is better so space chars are quoted if necessary.</p>

<p>(BTW since you prefix your command by <code>bash</code> you don't need the <code>shell=True</code>)</p>

<p>Third alternative: let the system choose which interpretor to use according to the shebang:</p>

<pre><code>def downloadURL(self,address):
        call(['youtube2mp3_2.sh',address],shell=True)
</code></pre>

<p>PS: The args you're passing <code>['bash youtube2mp3_2.sh', str(address)]</code> make <code>call</code> add quotes to the first one because it contains spaces, well I don't know what the hell happens on Linux, but I tested on windows and I got a "syntax error", nothing got executed. (Works with the fixed code, I have MSYS <code>bash</code> in my path)</p>

<p>PS2: why calling such a simple bash script from python. Do it in python:</p>

<pre><code>def downloadURL(self,address):
   path_music="/home/pi/music_loaded"
   rc=call(["youtube-dl","--no-playlist","-x","--audio-format","mp3","-o",os.path.join(path_music,'%(title)s.%          (ext)s'),address])
   if rc==0:
      print("Download OK")
</code></pre>

python bash youtube-dl