具有相对路径和关闭命令提示符的批处理文件 [英] batch file with relative path and close command prompt

查看:64
本文介绍了具有相对路径和关闭命令提示符的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以下代码:

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

基于:在命令提示符下运行.exe的蝙蝠文件

但是,我想成为相对路径,像这样:

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

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

基于: BAT脚本中的相对路径

但是什么也没发生.那么,有人可以给我信息,怎么了?

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

推荐答案

打开命令提示符窗口,然后运行 start/?.这将输出命令 START 的帮助,使用该命令时应阅读该帮助以了解有关其选项的信息.

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.

在命令提示符窗口中运行 call/?并阅读输出帮助页面以了解%〜dp0 .批处理文件的驱动器和路径(参数0)始终以反斜杠结尾.因此,不要在将其与另一个字符串连接时添加额外的反斜杠.

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.

第一个双引号字符串由 START 解释为在新窗口的标题栏中显示的新控制台窗口的标题.因此,最好在启动GUI应用程序时根本没有打开任何控制台窗口的情况下,始终指定标题字符串,也可以是空字符串,例如" .

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

根据/D%〜dp0DATA \ QGIS2 \ bin" 的定义,此处从目录开始根据命令 START 作为一个参数字符串.

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.

但是Windows命令解释器也接受带有选项/D 的第一个变体,但不带任何文件夹路径,而在下一个参数字符串%〜dp0DATA \ QGIS2 \ bin" 分隔空间是从目录开始的文件夹路径.

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.

/D 作为一个参数字符串和%〜dp0DATA \ QGIS2 \ bin" 作为一个参数字符串的第一个变量相比,它更易于阅读第二个变体,其中/D%〜dp0DATA \ QGIS2 \ bin" 仅是一个参数字符串.

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.

这篇关于具有相对路径和关闭命令提示符的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆