title: Python. Calling openssl.exe in Windows
body: <p>I have a Python script that needs to call openssl.exe in Windows. Here's the script:</p>
  <pre><code>import os
  import subprocess
  #print(&quot;Starting startfile method&quot;)
  #os.startfile('openssl.exe req -out server.csr -newkey:4096 -nodes -keyout server.priv.key -config server.cnf')
  #print(&quot;Starting Popen method&quot;)
  #subprocess.Popen('openssl.exe req -out server.csr -newkey rsa:4096 -nodes -keyout server.priv.key -config server.cnf')
  #print(&quot;Starting run method&quot;)
  #subprocess.run(['openssl.exe', 'req -out server.csr -newkey rsa:4096 -nodes -keyout server.priv.key -config server.cnf'])
  #print(&quot;Starting call method&quot;)
  #subprocess.call('openssl.exe req -out server.csr -newkey rsa:4096 -nodes -keyout server.priv.key -config server.cnf')
  #print(&quot;Done&quot;)
  </code></pre>
  <p>If I uncomment the &quot;os.startfile&quot; line, I get a file not found error. That makes sense. os.startfile can't handle arguments (is that correct?)</p>
  <p>If I uncomment the subprocess.Popen line, openssl starts, performs as it should, then hangs. openssl.exe process never exits, and so the script doesn't finish. That really perplexes me.</p>
  <p>If I uncomment the subprocess.run line, then openssl.exe gives me an error that &quot;req -out... is not a valid command&quot; Is that because openssl.exe doesn't like arguments given through stdin?</p>
  <p>If I uncomment the subprocess.call line, openssl.exe behaves exactly as it should (that is, as if it were run from Windows command line), and it exits and allows the Python script to continue.</p>
  <p>Can you help me understand the differences between the these different methods of calling external processes?</p>