如何在批处理文件中提供相对路径?

use*_*397 2 batch-file

我正面临下面的批处理脚本的问题,我必须在我的批处理文件中给出硬编码路径的相对路径.

下面是我的soapUI cmd行执行文件,其中soapui-settings.xml是包含我所有soap设置的文件,project.xml是我的testcases.我这里有硬编码路径.因为我要检查这个文件,如果任何其他人执行这个文件将无法工作,因为他们的机器上不存在该路径.我如何在Windows上实现这一目标?有没有办法可以在我的批处理文件中使用硬编码的相对路径并运行它?

这是我的示例文件:

cd C:\soapui4.5\soapUI-Pro-4.5.0\bin  
testrunner.bat -tC:\Users\jvihol\soapui-settings.xml C:\Users\jvihol\Documents\April-RTM-soapui-project.xml
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.谢谢.:)

ixe*_*013 5

这是我用来解决变化路径的技巧.简而言之,

  1. 创建相对于批处理文件位置的所有路径,以及
  2. 使批处理文件更改其自己的工作目录.

如果您调用的工具位于路径中,或者位于由环境变量定义的位置,则会有所帮助.

像这样的东西:

@echo off

pushd %~dp0

REM Here you are executing in the same directory as the batch file
REM You can make your path relative to here

popd
Run Code Online (Sandbox Code Playgroud)

对于您的项目,您可以使用相同%~dp0的占位符作为绝对路径.

pushd C:\soapui4.5\soapUI-Pro-4.5.0\bin 
testrunner.bat -EDefault -I -t%~dp0soapui-settings.xml %~dp0April-RTM-soapui-project.xml
popd
Run Code Online (Sandbox Code Playgroud)