Passing arguments to argparse from subprocess.Popen
<p>I am trying to call a script using python 2 (say scriptA) from within another script(scriptB) using the subprocess.Popen functionality in python 3</p>

<p>The script that I wish to call implements an argparse method which expects two arguments something like below:
ScriptA (needs python 2):</p>

<pre><code>def get_argument_parser():
'''
'''
import argparse

parser = argparse.ArgumentParser("Get the args") 

parser.add_argument("-arg1", "--arg1",required = True,
                    help = "First Argument")

parser.add_argument("-arg2", "--arg2",required = True,
                    help = "Second Argument")

return parser
</code></pre>

<p>Now, I am calling the above script using subprocess as follows:
ScriptB:</p>

<pre><code>value1 = "Some value"
value2 = "Some other value"
subprocess.Popen(["C:\\Python27\\python.exe ", ScriptAPATH, " -arg1 " , value1, " -arg2 ", value2],shell = True, stdout = subprocess.PIPE)
</code></pre>

<p>However, I am getting an error that:
error: argument -arg1/--arg1 is required</p>

<p>What I tried next is to replace subprocess.Popen with os.system something like below:</p>

<pre><code>cmd = "C:\\Python27\\python.exe scriptA.py" + " -arg1 " + value1 + " -arg2 " + value2
os.system(cmd)
</code></pre>

<p>This works fins and I am able to access the arguments from ScriptA in this case. 
Any pointers as to what could be going wrong in the first case? I am kind of new to python so any sort of help would be appreciated </p>