Passing Parameters to .bat file
Hi,
I'm trying to execute a bat file, but it needs to know some information... how can I pass parameter to a .bat file... the following is not working:
String[] commands ={"cmd.exe","/c", batFilePath,"C:\\Documents and Settings\\BLogan4\\console_docs\\"};
try{
Runtime.getRuntime().exec(commands);
}catch(IOException iox){iox.printStackTrace();}
here are the contents of the bat file:
@echo off
cd %0
jar xf"docs.jar"
I just want to cd from working dir to the proper dir and unzip this jar file...
advTHANKSance
Thanks Turing,
But, the quotes did not work. I think this is by design (albeit a poor one)
just as using 'start /Dpath ...' does not accept paths with spaces in them ~> http://www.ss64.com/nt/start.html
"Note that START /D does not support long filenames which contain spaces, a workaround is to use the 8.3 compatible name(s)"
My workaround for this case was to simply generate the bat file from within the java code, including the correct working directories... Then use: String[] commands = {"cmd.exe","/c",quotedBatFilePath};
try{
Runtime.getRuntime().exec(commands);
}catch(IOException iox){iox.printStackTrace();}
to execute the file... *Note* the quotes do work here! They just don't seem to work when passing args to a bat file...
-Regards
This whole question was raised due to difficulties I encountered using start /Dpath... I needed a way to set the working directory...
Aside from generating the .bat on demand, I thought to accept many parameters in the bat and concatenate them.. (If the string was broken up into smaller substrings due to spaces, it would be reconstructed)
Turing Pest:
Sorry for calling you Turing instead of the full 'Turing Pest'... Perhaps this was inappropriate being that you are not in fact Alan Turing. I did not mean to break the pun... :)
Regards,
TheMagician