CreateProcess (docs) which (appears to?) only identify
.exe files by default. Therefore when trying to run something like the
heroku CLI using
subprocess.run('heroku') it fails with
[WinError 2] The system cannot find the file specified. Using
where heroku I can see that it has two executables at:
C:\Program Files\heroku\bin\heroku C:\Program Files\heroku\bin\heroku.cmd
shell=True fixes this because the shell (
cmd.exe /c) resolves these paths, while
CreateProcess doesn’t. However, I can resolve these using another Python tool and avoid introducing the security issues and overhead of
shell=True by using the
shutil.which method (docs).
Combined, the full command would be:
Written by Alex Wendland, who is currently exploring fintech at Pinwheel. Here's a Twitter handle, a GitHub, some LinkedIn, ol' Facebook, or a hip Instagram if you're interested.