spliting the passed arguments

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bugsdeepak
Posts: 1
Joined: 30 Nov 2009 06:19

spliting the passed arguments

#1 Post by bugsdeepak » 30 Nov 2009 06:36

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
........

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 02 Dec 2009 13:52

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
........

Post Reply