Page 1 of 1

spliting the passed arguments

Posted: 30 Nov 2009 06:36
by bugsdeepak
Hello There,

My requirement is, the muliple arguments (JVM) that is passed to the batch file with double quotes should be passed to the JVM, when invoking the main Java file.

For example:
if i call my batch file like:

mybat.bat -vm "-Xms12m -Xmx1024m -esa"

Then the above three arguments should be passed to the Java VM.
But when I did the simple thing (Get the argument remove quote and pass it to VM) I got the following error.

"-Xmx1024m was unexpected at this time"

The Batch file looks like this

if "%1" == "-vm" goto %1

.........
.......
:-vm
shift
set VMARGS=%~1
........
.......

java %VMARGS% MyProg
........

Posted: 02 Dec 2009 13:52
by avery_larry
Why shift? Just use %~2


Code: Select all

if "%1" == "-vm" goto %1 

.........
.......
:-vm
set "VMARGS=%~2"
........
.......

java %VMARGS% MyProg
........



Alternative (untested):

mybat.bat -vm -Xms12m -Xmx1024m -esa

Code: Select all

if "%1" == "-vm" goto %1 

.........
.......
:-vm
shift
set "VMARGS=%*"
........
.......

java %VMARGS% MyProg
........