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

[884 byte] By [BlairTheMagiciana] at [2007-11-27 5:02:55]
# 1
you can pass parameters to a bat file. try it in the command prompt first. http://home.att.net/~gobruen/progs/dos_batch/dos_batch.html#param
TuringPesta at 2007-7-12 10:20:57 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks TP.. My problem is that I am passing in a path name that includes spaces as the parameter... the parameter is being truncated to C:\Documents instead of 'C:\Documents and Settings...."I am looking into a workaround... any ideas?Thanks,B
BlairTheMagiciana at 2007-7-12 10:20:57 > top of Java-index,Java Essentials,Java Programming...
# 3
yea theyre called quotes my brutha'. once again, learn how to do this in command prompt first.
TuringPesta at 2007-7-12 10:20:57 > top of Java-index,Java Essentials,Java Programming...
# 4

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

BlairTheMagiciana at 2007-7-12 10:20:57 > top of Java-index,Java Essentials,Java Programming...
# 5

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

BlairTheMagiciana at 2007-7-12 10:20:57 > top of Java-index,Java Essentials,Java Programming...