title: Using a Windows path within Python's subprocess (point to an executable)
body: <p>I started developing a small pdf to jpg script on a Windows 7 x64 machine with cygwin installed (Python 2.7). The following works perfectly:</p>
  <pre><code>import subprocess
  filename = &quot;test&quot;
  subprocess.check_output('gs -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o ' + filename + '-2800-%03d.jpg ' + filename + '.pdf', stderr=subprocess.STDOUT)
  </code></pre>
  <p>After pulling this project on my Windows 10 x64 non-Cygwin machine (Python 2.7), this code errors as it no longer recognizes &quot;gs&quot; as a built-in short for ghostscript. So I try the following:</p>
  <pre><code>import subprocess
  filename = &quot;test&quot;
  subprocess.check_output('C:\Program Files\gs\gs9.20\bin\gwin64c.exe -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o ' + filename + '-2800-%03d.jpg ' + filename + '.pdf', stderr=subprocess.STDOUT)
  
  WindowsError: [Error 2] The system cannot find the file specified
  </code></pre>
  <p>Ok fine, I am a beginner and making some obvious mistake here. Also the <code>&quot;\b&quot;</code> characters in between <code>.20\bin\</code> are highlighted ... indicating to me I somehow haven't made clear this is a single path.</p>
  <p>Things I have also tried (separate runs):</p>
  <pre><code>subprocess.check_output(r'C:\Program Files\gs\gs9.20\bin\gwin64c.exe -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o ' + filename + '-2800-%03d.jpg ' + filename + '.pdf', stderr=subprocess.STDOUT')
  
  subprocess.check_output(&quot;C:\Program Files\gs\gs9.20\bin\gwin64c.exe -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o ' + filename + '-2800-%03d.jpg ' + filename + '.pdf', stderr=subprocess.STDOUT/s&quot;, shell=True)
  </code></pre>
  <p>I have read:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/15207271/how-to-use-the-dir-s-command-in-python">How to use the dir/s command in Python?</a></li>
  <li><a href="https://stackoverflow.com/questions/5486725/how-to-execute-a-command-prompt-command-from-python">How to execute a command prompt command from python</a></li>
  <li><a href="https://stackoverflow.com/questions/2028207/wrapping-cmd-exe-with-subprocess">wrapping cmd.exe with subprocess</a></li>
  <li><a href="https://stackoverflow.com/questions/26774488/python-subprocess-does-not-take-correct-arguments">Python subprocess does not take correct arguments</a></li>
  <li><a href="https://stackoverflow.com/questions/2028207/wrapping-cmd-exe-with-subprocess">wrapping cmd.exe with subprocess</a></li>
  </ul>
  <p>to no avail</p>
  <p>The error given always is:</p>
  <pre><code>Traceback (most recent call last):
  File &quot;C:/Python/Project/projectx/manual_conversion/manual_conversion.py&quot;, line 16, in &lt;module&gt;
  subprocess.check_output(r'C:\Program Files\gs\gs9.20\bin\gwin64c.exe -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o ' + filename + '-2800-%03d.jpg ' + filename + '.pdf', stderr=subprocess.STDOUT)
  File &quot;C:\Python\Python 2.7.12\lib\subprocess.py&quot;, line 567, in check_output
  process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File &quot;C:\Python\Python 2.7.12\lib\subprocess.py&quot;, line 711, in __init__
  errread, errwrite)
  File &quot;C:\Python\Python 2.7.12\lib\subprocess.py&quot;, line 959, in _execute_child
  startupinfo)
  WindowsError: [Error 2] The system cannot find the file specified
  </code></pre>
  <p>I fully understand this is rookie stuff + switching to unix would make my life easier - but in my corporate environment I don't fully have that option.</p>
  <p>I have also tried:</p>
  <pre><code>subprocess.check_output(r'C:\Program Files\gs\gs9.20\bin\gwin64c.exe -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o 2800-%03d.jpg test.pdf')
  </code></pre>
  <p>Since I thought maybe my variable concatenation was breaking the command ... but this again yields the same error.</p>
  <p>EDIT 2: Passing the full argument as a list</p>
  <pre><code>subprocess.check_output([r'C:\Program Files\gs\gs9.20\bin\gswin64c.exe -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o 2800-%03d.jpg test.pdf'])
  </code></pre>
  <p>Yields the same error. But this:</p>
  <pre><code>subprocess.check_output([r'C:\Program Files\gs\gs9.20\bin\gswin64c.exe'])
  </code></pre>
  <p><strong>Does start up ghostscript in Windows</strong>. Thank you @lit for making me try things, now the new problem is how to pass options to <code>subprocess</code>' check_output executable.</p>
  <p>Still bothers me how easy it worked on a Windows system simply because it had cygwin installed that somehow modified cmd namespace to recognize &quot;gs&quot;...</p>