batch file with relative path and close command prompt

会有一股神秘感。 提交于 2020-01-07 03:13:25

问题


I try this code :

start /d "D:\test\CONTOH\DATA\QGIS2\bin\" qgis.bat

based on : Bat file to run a .exe at the command prompt

But, I want to be relative path, something like this :

start /d %~dp0\DATA\QGIS2\bin\qgis.bat

based on : relative path in BAT script

but, nothing happen. So, can someone give me information, what is wrong?


回答1:


Open a command prompt window and run start /?. This outputs the help for the command START which should be read on using this command to get knowledge about its options.

Run in command prompt window call /? and read the output help pages to understand %~dp0. The drive and path of the batch file (argument 0) always ends with a backslash. Therefore don't add an extra backslash on concatenating it with another string.

And the first double quoted string is interpreted by START as title for the new console window displayed in title bar of the new window. Therefore better specify always a title string which can be also an empty string like "" in case of starting a GUI application on which no console window is opened at all.

start "Running QGIS2" /D "%~dp0DATA\QGIS2\bin" qgis.bat

Also possible is using this command line in batch file:

start "Running QGIS2" /D"%~dp0DATA\QGIS2\bin" qgis.bat

Here start in directory as defined with /D"%~dp0DATA\QGIS2\bin" is 100% correct specified according to help of command START as one parameter string.

But Windows command interpreter accepts also the first variant with just option /D without any folder path and next parameter string "%~dp0DATA\QGIS2\bin" after a separating space is the folder path for start in directory.

The first variant with just /D as one parameter string and "%~dp0DATA\QGIS2\bin" as one more parameter string is easier to read in comparison to second variant with /D"%~dp0DATA\QGIS2\bin" being just one parameter string.



来源:https://stackoverflow.com/questions/42219419/batch-file-with-relative-path-and-close-command-prompt

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