title: Python subprocess can't call "ssh"
body: <p>I'm working on using the subprocess module to send shell commands from Python, specifically, <code>ssh</code>. Below is a barebones sample:</p>
  <pre><code>import subprocess
  
  sp = subprocess.run([&quot;ssh&quot;], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  print(f&quot;stdout: {sp.stdout.decode()} \n\nstderr: {sp.stderr.decode()}&quot;)
  </code></pre>
  <p>This should return the ssh command help from stdout, and nothing from stderr. However, I get:</p>
  <pre><code>stdout:  
  
  stderr: 'ssh' is not recognized as an internal or external command,
  operable program or batch file.
  </code></pre>
  <p>I've tried other commands, like <code>echo</code> and <code>cd</code>, and those work fine. I am also able to use <code>ssh</code> when manually typing the command into the shell, but it fails when I try to do it through subprocess. The directory <code>C:\Windows\System32\OpenSSH</code> does exist on my computer (and it contains <code>ssh.exe</code>), but for some strange reason I'm unable to cd to it using subprocess.</p>
  <p>If it matters, subprocess is using the command prompt, <code>cmd.exe</code>, as it seems to be the default.</p>
  <p>Any help is appreciated. Thanks!</p>
  <p>-- Edits with tests from comments --</p>
  <ul>
  <li>Using the absolute path <code>C:/Windows/System32/OpenSSH/ssh.exe</code> does not work, and gives <code>The system cannot find the path specified</code> via stderr. The <code>OpenSSH</code> folder doesn't seem to be visible to Python through subprocess</li>
  <li><code>os.environ[PATH]</code> contains both <code>C:/Windows/System32/</code> and <code>C:/Windows/System32/OpenSSH/</code></li>
  <li>Running it with <code>shell=False</code> (either with the absolute path or just with <code>ssh</code>) raises an error in Python: <code>FileNotFoundError: [WinError 2] The system cannot find the file specified</code></li>
  </ul>