简体   繁体   English

在Windows命令提示符下运行命令之前如何更改目录

[英]how to change directory before running command in windows command prompt

# 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" . 问题>我需要将工作目录更改为C:\\Program Files (x86)\\XXX\\然后运行命令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. 例如,如果我运行c:\\ temp \\ run.bat,我希望脚本首先更改为C:\\Program Files (x86)\\XXX\\然后运行python脚本。

Step 1: Find the short names for the directory with space 步骤1:使用空格查找目录的简称

dir /X
PROGRA~2     Program Files (x86)

Step 2: Quote all commands 步骤2:引用所有命令

cmd /k "cd C:\PROGRA~2\XXX\ & python.exe C:\PROGRA~2\XXX\test.py"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM