title: How not to escape an ampersand with python subprocess
body: <p>I'd like to execute with <code>subprocess.Popen()</code> this command containing an ampersand to be interpreted as a batch concatenation operator:</p>
  
  <pre><code>COMMAND="c:\p\a.exe &amp; python run.py"
  subprocess.Popen(COMMAND,cwd=wd,shell=False)`
  </code></pre>
  
  <p>The ampersand <code>&amp;</code> however is interpreted as an argument of <code>a.exe</code> and not as a batch operator.</p>
  
  <p><strong>Solution 1:</strong> Having seen the related <a href="https://stackoverflow.com/questions/120657/python-subprocess-issue-with-ampersands" title="question">question</a>, a solution could be to set <code>shell=True</code> but that gives the error 'UNC path are not supported', since my working directory is remote. This solution does not work as it is.</p>
  
  <p><strong>Solution2:</strong> The executable <code>a.exe</code> should take a <code>-inputDir</code> parameter to specify the remote location of the files and use a local working directory. I think this solution could work but I may not have the source code of the executable.</p>
  
  <p><strong>Solution3:</strong> I could instead write <code>c:\p\a.exe &amp; python run.py</code> into <code>command.bat</code> and then use</p>
  
  <pre><code>COMMAND="c:\p\command.bat"
  subprocess.Popen(COMMAND,cwd=wd,shell=False)`
  </code></pre>
  
  <p>Could this approach work?</p>
  
  <p><strong>Solution4:</strong> I am trying to solve this changing only the <code>subprocess.Popen()</code> call. Is it possible to do it? Based on the <a href="https://docs.python.org/3/library/subprocess.html#popen-constructor" rel="nofollow noreferrer">python Popen doc</a> I suspect is not possible. Please tell me I am wrong.</p>
  
  <p>See also <a href="https://stackoverflow.com/questions/295459/how-do-i-use-subprocess-popen-to-connect-multiple-processes-by-pipes" title="This">this</a> related questions. </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Solution 5: @mata suggested to use Powershell <code>Popen(['powershell', '-Command', r'C:\p\a.exe; python run.py'])</code>. This actually works, but now I have to deal with slightly different commands, and being lazy I've decided to use solution 3.</p>
  
  <p>My favourite solution was Solution 3, to create a <code>.bat</code> file and call it </p>
  
  <pre><code>COMMAND="c:\p\command.bat"
  subprocess.Popen(COMMAND,cwd=wd,shell=False)
  </code></pre>