title: Python Popen hangs, yet same command in Windows cmd window runs fine
body: <p>I am pulling my hair out here.  I am spawning a process which I need the feedback from in Python.  </p>
  
  <p>When I run the command in the cmd window it runs fine, but when I try to run it via Python the terminal hangs.</p>
  
  <pre><code>p = subprocess.Popen(startcmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  (out, err) = p.communicate()
  </code></pre>
  
  <p>Where <code>startcmd</code> is a string which when printed in the Python console looks like this:</p>
  
  <pre><code>"C:/Program Files/GRASS GIS 7.2.1/grass72.bat" --version
  </code></pre>
  
  <p>If I copy and paste this into a Windows cmd, it shows the version information and returns control to the command prompt about a second later, but in Python it freezes up.</p>
  
  <p>I should point out, if I replace the <code>startcmd</code> string with something like <code>"dir"</code> or even <code>"python --version"</code>, it works fine!</p>
  
  <p><strong>Additional:</strong> I have tried <code>shell=True</code>, this has the same result.</p>
  
  <p><strong>Additional:</strong> I have tried sending the cmd and arguments through as an array as suggested in an answer below given that <code>shell=False</code>, but this also hangs the same.</p>
  
  <p><strong>Additional:</strong> I have added the GRASS path to the system PATH, so that now I can simply call <code>grass72 --version</code> in the cmd window to get a result, however this also still freezes in Python but works fine in cmd.</p>
  
  <p><strong>Additional:</strong> I have created a basic .bat file to test if .bat files run ok via Python, here is what I created:</p>
  
  <pre><code>@echo off
  title Test Batch Script
  echo I should see this message
  </code></pre>
  
  <p>This runs fine both in cmd, and in Python.</p>
  
  <p><strong><em>Problem found but not solved!</em></strong></p>
  
  <p>So, I'm running the script which spawns the process using <code>subprocess.Popen</code> using Python 3.6.  The .bat file which is spawned launches a Python script using a version of Python (based on 2.7) which comes shipped with GRASS:</p>
  
  <pre><code>%GRASS_PYTHON% "\BLAH\BLAH\grass72.py"
  </code></pre>
  
  <p>What is interesting, is that if I launch the <code>subprocess.Popen</code> script with Python 2.7, it works fine.  Ahah, you may think, solved!  But this doesn't solve my problem - because I really need Python 3.6 to be launching the process, also why does it matter what version of Python launches the batch file?  The new Python script which is spawned is launched with Python 2.7 anyway.</p>
  
  <p>Since I started re-directing stdout I can see that there is an error when I use Python 3.6 to launch the process:</p>
  
  <pre><code> File "C:\ProgramData\Anaconda3\lib\site.py", line 177
      file=sys.stderr)
          ^
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>Notice its reverting to Anaconda3!  Even though it is launched using python.exe from 2.7!</p>