Batch file command line args
|
Original Message
|
Name: nhanhamnho
Date: November 2, 2002 at 14:06:29 Pacific
Subject: Batch file command line args OS: Windows XP CPU/Ram: P3/384
|
Comment: I'm writing a java program that will take info from the command line and i'm required to make a batch file so that we dont need the java ... clause I'm not very familiar with Dos, what i need from the batch is just take whatever user type from the command line and pass it to the java command. say : if user type myProg arg1 arg2 arg3 arg4 the batch shoul convert that to java myProg arg1 arg2 arg3 arg4 Please help Thanks a lot
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: mm_freak
Date: November 3, 2002 at 01:51:27 Pacific
Subject: Batch file command line args
|
Reply: (edit)In batch files you can refer to command line arguments with %. Example: @echo off echo j | deltree %1 > nul The %1 in the batch file will be replaced by the first argument. %0 is the batch-file itself. The argument range goes from 0 to 9. If you need more args, you can use the shift command, which would move the value in %1 to %0, the one in %2 to %1 and so on, %9 would be the next argument. This way, you can load the entire command line into an environment variable: if "%1"=="" goto nxt :rep set tempvar=%tempvar% %1 shift if not "%2"=="" goto rep :nxt java myProg %tempvar% set tempvar=
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: mm_freak
Date: November 3, 2002 at 01:54:49 Pacific
Subject: Batch file command line args
|
Reply: (edit)Sorry, that batch file wouldn't work, if should be the following: :rep shift set tempvar=%tempvar% %0 if not "%1"=="" goto rep java myProg %tempvar% set tempvar=
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: