How to change to a subdirectory and run an exe using a bat file in a Windows 7 system?

不羁的心 提交于 2019-12-10 18:14:18

问题


Using a bat file, I want to change to a sub directory of folder which bat file is in, and run my_application.exe in that directory,

I try:

cd /d %cd%\my subdirectory
START %~dp0my_application.exe

But it doesn't work, it says it can't find my_application.exe


回答1:


Just indicate to start command what program to start and what should be the starting folder for it.

Without the cd command, it can be written as

start "" /d "%~dp0my_subdirectory" "my_application.exe"

if the my_application.exe is located in the subdirectory, or

start "" /d "%~dp0my_subdirectory" "%~dp0my_application.exe"

if the application is located in the same folder as the batch file.

start command take the first quoted parameter as the title for the new process. To avoid problems, a empty string ("") is included in command as the title.




回答2:


Try:

cd /d "%~dp0my_subdirectory"
start "" my_application.exe

or just:

start "" "%~dp0my_subdirectory\my_application.exe"


来源:https://stackoverflow.com/questions/22297542/how-to-change-to-a-subdirectory-and-run-an-exe-using-a-bat-file-in-a-windows-7-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!