Results 1 to 2 of 2
  1. #1
    vipvan2000 is offline Member
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    rajiv_bang is offline Member
    Join Date
    Nov 2007
    Posts
    11
    Rep Power
    0

    Default

    Hi,

    You can improve the code below and use. This is just indicative.

    Java 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

Similar Threads

  1. Command line argument
    By denisatandi in forum New To Java
    Replies: 8
    Last Post: 10-17-2012, 12:37 AM
  2. Replies: 4
    Last Post: 04-15-2008, 02:04 PM
  3. How to resolve Constructor argument in Spring
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-29-2008, 01:43 PM
  4. Parsing Argument Values
    By vipvan2000 in forum Advanced Java
    Replies: 1
    Last Post: 02-17-2008, 02:41 AM
  5. How to resolve Constructor argument in Spring
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 09:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •