Passing arg to subprocess.call
<p>I have a series of scripts that get called in an explicit order by another <code>run.py</code>. </p>

<p>Inside <code>run.py</code> I have the following:</p>

<pre><code>script1 = str(sys.path[0]) + "\\script1.py"
subprocess.call(["Python", script1])
</code></pre>

<p>And so on for 3 scripts. If I would like to pass two arguments to script 1 in this format, arguments such as explicit run settings to be used in the script when it is executing, how would I do this? I have a feeling it would rely on sys.argv within script1, but have gotten errors about the argument being out of range regardless of what index position I pass.</p>

<p>Thanks!</p>

<p>Subprocesses takes a list of arguments, which it then turns into a command it executes.</p>

<p>So:</p>

<pre><code>subprocess.call(["Python", script1, 'arg1', 'arg2'])
</code></pre>

<p>To <code>subprocess.call</code>, <em>all</em> the parts of its list are arguments. You just happen to be specifying "Python" and script1, but to subprocess, both are just other arguments.</p>

<p>There is a lot more reading on the <a href="https://docs.python.org/2/library/subprocess.html#using-the-subprocess-module" rel="nofollow">documentation for subprocess</a> which I would recommend looking over.</p>

python subprocess exec call sys