-
Parsing Argument Values
We use command line scripts to pass values like
java submit <input_file=test1> <output_dir=dir_name>
I have a need to pass the argument values to another program. How do I parse these values.
Sorry if it was asked earlier but I am very new to Java.
Thanks in advance
-
Hi,
You can improve the code below and use. This is just indicative.
Code:
public class ParseOptions {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String input_file = args[0].split("=")[1];
String dest_dir = args[1].split("=")[1];
System.out.println("input_file "+input_file);
System.out.println("dest_dir "+dest_dir);
}
}
But an elegant way to do this would be to use one of the open source command line frameworks like Apache Commons.
HTH