Can't run files with space in path via external terminal
See original GitHub issueI dumped the cmd being called from spyder.util.programs (line 764ish) with a simple print statement, and nothing seems immediately wrong, but [WinError 267] The directory name is invalid
is consistently thrown.
Cmd:
start cmd.exe /K “cd “Y:\Users\aaron\python scripts” && “C:\Users\aaron\python\py39\python.exe” -i “Y:\Users\aaron\python scripts\helloworld.py”” ^&^& exit
I can even separately copy and paste the command into a different terminal (just python inside cmd; no IDE) and call the following without issue:
from subprocess import Popen
Popen(r'start cmd.exe /K "cd "Y:\Users\aaron\python scripts" && "C:\Users\aaron\python\py39\python.exe" -i "Y:\Users\aaron\python scripts\helloworld.py"" ^&^& exit', shell=True)
Including the cwd
arg does not make a difference either when using Popen myself, but if I modify spyder.utils.programs.py at line 762 to be:
try:
# if wdir:
# run_shell_command(cmd, cwd=wdir)
# else:
run_shell_command(cmd)
the problem is solved.
Am I missing something, or does the “cd” command included in the cmd
string take care of not needing the cwd
argument? I also cannot figure out why it’s an issue for spyder to include cwd
but not when I do it in a terminal myself…
- Spyder version: 5.3.0 None
- Python version: 3.9.6 64-bit
- Qt version: 5.12.10
- PyQt5 version: 5.12.3
- Operating System: Windows 10
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
@mrclary, could you give us a hand with this one, since it seems you understand well what needs to be done? Thanks!
You are correct. I miss-read the code.
Yes, I think it most pythonic to use the
cwd
keyword argument wherever possible; it likely requires unquoted string for all platforms, but should be verified. For linux, then,wdir-option
could be removed andcd
should be removed from both nt and darwin, withcwd
added to the darwin case. The temporary file may not be necessary for darwin either, but I’d have to verify the interaction of Terminal.app with the providedenv
keyword forPopen
…