How to use the subprocess.check_output comand correctly
<p>I want to execute the the shell script <code>generateLicense.sh</code> with different arguments. I do it like that:</p>

<pre><code>License = subprocess.check_output(['./generateLicense.sh -firstargument 1 -secondargument 2 -thirdargument 3'])
</code></pre>

<p>The shell script is in the same folder as the file that starts the shell script but i always get this error:</p>

<pre><code>OSError: [Errno 2] No such file or directory
</code></pre>

<p>Using <a href="https://docs.python.org/3/library/subprocess.html#subprocess.check_output" rel="nofollow">check_output</a> the way you are trying to, each command has to be an item in the list you are passing. So, what you should have is: </p>

<pre><code>License = subprocess.check_output(['./generateLicense.sh', '-firstargument', '1', '-secondargument', '2', '-thirdargument', '3'])
</code></pre>

<p>Here is a replication of your problem using a different command to showcase what is happening when you pass a multi-argument command as a single string in the list being passed to <code>check_output</code>: </p>

<pre><code>&gt;&gt;&gt; import subprocess
&gt;&gt;&gt; subprocess.check_output(["ls -a"])
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
</code></pre>

<p>Doing this in Python 3 you will actually get something more coherent: </p>

<pre><code>FileNotFoundError: [Errno 2] No such file or directory: 'ls -a'
</code></pre>

python shell subprocess