python: trouble with Popen FileNotFoundError: [WinError 2]
<p>I've search a while and still can not figure it out...
Here's part of my code that went wrong.</p>

<pre><code>import subprocess as sp
import os
cmd_args = []
cmd_args.append('start ')
cmd_args.append('/wait ')
cmd_args.append(os.path.join(dirpath,filename))
print(cmd_args)
child = sp.Popen(cmd_args)
</code></pre>

<p>And the command prompt through out this.</p>

<pre><code>['start ', '/wait ', 'C:\\Users\\xxx\\Desktop\\directory\\myexecutable.EXE']
Traceback (most recent call last):
  File "InstallALL.py", line 89, in &lt;module&gt;
    child = sp.Popen(cmd_args)
  File "C:\Python34\lib\subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1114, in _execute_child startupinfo)
FileNotFoundError: [WinError 2]
</code></pre>

<p>It looks like the filepath is wrong with 2 backslashes.</p>

<p>I know if I do </p>

<pre><code>print(os.path.join(dirpath,filename))
</code></pre>

<p>It'll return </p>

<pre><code>C:\Users\xxx\Desktop\directory\myexecutable.EXE
</code></pre>

<p>I'm sure the file is there. 
How can I debug this?</p>

<p>This is happening because <code>Popen</code> is trying to find the file <code>start</code> instead of the file you want to run.</p>

<p>For example, using <code>notepad.exe</code>:</p>

<pre><code>&gt;&gt;&gt; import subprocess
&gt;&gt;&gt; subprocess.Popen(['C:\\Windows\\System32\\notepad.exe', '/A', 'randomfile.txt']) # '/A' is a command line option
&lt;subprocess.Popen object at 0x03970810&gt;
</code></pre>

<p>This works fine. But if I put the path at the end of the list:</p>

<pre><code>&gt;&gt;&gt; subprocess.Popen(['/A', 'randomfile.txt', 'C:\\Windows\\System32\\notepad.exe'])
Traceback (most recent call last):
  File "&lt;pyshell#53&gt;", line 1, in &lt;module&gt;
    subprocess.Popen(['/A', 'randomfile.txt', 'C:\\Windows\\System32\\notepad.exe'])
  File "C:\python35\lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "C:\python35\lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
</code></pre>

<p>Use this instead:</p>

<pre><code>import subprocess as sp
import os
cmd_args = []
cmd_args.append(os.path.join(dirpath,filename))
cmd_args.append('start ')
cmd_args.append('/wait ')
print(cmd_args)
child = sp.Popen(cmd_args)
</code></pre>

<p>You might need to swap <code>cmd_args.append('start ')</code> and <code>cmd_args.append('/wait ')</code> around too depending on which order they are meant to be in.</p>

python