# run.bat
cmd /k python.exe "C:\Program Files (x86)\XXX\test.py"
cmd /k cd "C:\Program Files (x86)\XXX\" & python.exe "C:\Program Files (x86)\XXX\test.py"
cmd /k "cd "C:\Program Files (x86)\XXX\" & python.exe "C:\Program Files (x86)\XXX\test.py""
Question> I need to change the working directory to C:\\Program Files (x86)\\XXX\\
then run the command python.exe "C:\\Program Files (x86)\\XXX\\test.py"
. Several methods have been tested and none of them give me the desired result. They all end up run the command without changing the working directory.
For example, If I run c:\\temp\\run.bat, I expect the script first to change to directory of C:\\Program Files (x86)\\XXX\\
then run the python script.
Step 1: Find the short names for the directory with space
dir /X
PROGRA~2 Program Files (x86)
Step 2: Quote all commands
cmd /k "cd C:\PROGRA~2\XXX\ & python.exe C:\PROGRA~2\XXX\test.py"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.