3

I am facing an issue with below batch script where i have to give a relative path of the hard-coded path in my batch file.

below is my soapUI cmd line execution file where soapui-settings.xml is the file which has all my soap settings and project.xml is the one with my testcases. I have hard-coded path here. since i am going to check in this file, if any other person execute this file will not work because the path will not exist on their machine. How do i achieve that on windows? Is there a way I can use a relative path to hard-coded one in my batch file and run it??

here is my sample file:

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 

any help would be really appreciated. thanks. :)

2
  • Thanks Chuck. So i have modified batch file to look like below: cd C:\soapui4.5\soapUI-Pro-4.5.0\bin testrunner.bat -EDefault -I -t..\..\soapui-settings.xml ..\..\April-RTM-soapui-project.xml I still get file not found or failed to load my project.xml file when I run it. any ideA? Commented May 23, 2012 at 1:53
  • There are some type in your sample file. Is it all of it ? Where is you batch file located, with regards to your *.xml files ? Commented May 23, 2012 at 3:10

3 Answers 3

5

Here is the trick I use to solve changing paths. In short,

  1. Make all path relative to the batch file location, and
  2. Make the batch file change its own working directory.

It helps if the tools you call are in the path, or in a location defined by an environment variable.

Something like this :

@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 

For your project, you can use the same %~dp0 as a place holder for the absolute path.

pushd C:\soapui4.5\soapUI-Pro-4.5.0\bin testrunner.bat -EDefault -I -t%~dp0soapui-settings.xml %~dp0April-RTM-soapui-project.xml popd 
Sign up to request clarification or add additional context in comments.

Comments

1

Getting an absolute path from a relative path requires somebody to do some calculation. The three options I know of are: i) an add-on program that does nothing but path calculations, ii) use the "current directory", and iii) smash the two paths together. Here are rough illustrations of methods ii) and iii):

REM example "givens" set DRIVE=C: set ROOTPATH=\fee\fie\fo set RELPATH=funky\stuff set FILENAME=blarf.txt REM method ii) using the "current directory" functionality %DRIVE% cd %ROOTPATH% cd %RELPATH% more %FILENAME% REM method iii) using explicit concatenation set FULLPATH=%DRIVE%%ROOTPATH%\%RELPATH% set PATHFILENAME=%FULLPATH%\%FILENAME% more %PATHFILENAME% REM DOS/BAT handling of drive letter is odd (is it part of the path, or not?) REM It may be necessary to use "cd /D ..." REM Path calculations are easier REM so long as DOS/BAT understands that "\\" is the same as "\" 

3 Comments

Thanks Chuck. So i have modified batch file to look like below: cd C:\soapui4.5\soapUI-Pro-4.5.0\bin testrunner.bat -EDefault -I -t..\..\soapui-settings.xml ..\..\April-RTM-soapui-project.xml I still get file not found or failed to load my project.xml file when I run it. any ideA?
Here's what I'd do: print out your BAT file, open a DOSBox, and type in the commands on your printed sheet one at a time to see what's happening and when an error occurs. Often it's hard to distinguish a problem in the BAT file itself from a problem with one of the tools invoked by the BAT file. What I suspect in this case is a typo. It's very easy (at least it is for me:-) to mix up dash and underscore, and is that RTM or RMT, etc.
Another thought: unlike most folks are used to, BAT files are very sensitive to white space betwen a flag and its argument, and there's no "standard" way, and they won't work if it's not as they expect. Maybe only "-t foo/bar" will work, or maybe only "-tfoo/bar" will work.
1

Maybe you want this:

cd C:\soapui4.5\soapUI-Pro-4.5.0\bin testrunner.bat -t%USERPROFILE%\soapui-settings.xml %USERPROFILE%\Documents\April-RTM-soapui-project.xml 

USERPROFILE is a system environment variable containing the path to the current user's home directory. In your session it will evaluate to

C:\Users\jvihol 

and in someone else's, to

C:\Users\someone else's user name 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.