Results 1 to 10 of 10
  1. #1
    joey86 is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Question Multi Valued Command Line arguments

    Hello friends,

    I got a query about passing multi valued command line arguments.
    I'll give the arguments to be passed for clear understanding of the question

    arguments are as follows:

    1)parameter 1
    2)parameter 2
    3)parameter 3
    4)parameter 4 which actually consists of values as follows:(multi-valued)

    Column1 Column2 Column3 Column4 Column5
    2 Y Some value 3 N
    1 N Null 4 Y
    3 N Null 1 Y
    4 Y Some value 2 N
    so i am looking for ways to handle such arguments from command line,
    any suggestion and help is appreciated.

    Thanks :)
    Joe

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    I'm not sure that it is good practice to have multi-value argument if you have
    to handle it on your own.

    Consider validation on input and parser that you must write to handle all
    5 columns in it.

    If you enter each of 5 Column arguments separately,
    you can easily validate it one by one and later bring them together and put in some data structure of yours.

    Problem is there will be to many of them at the end
    so your app. start command may look like:

    Java Code:
    java -jar myApp.jar -p1 value -p2 value -p3 value 
     -c1 value -c2 value -c3 value -c4 value -c5 value
    after that in your code you have to:

    1) check param names first


    Java Code:
    if (
     ...!args[0].equals("-p1") || 
    
    ...!args[7].equals("-c5") ||
    ) 
     displaySomeErrorMessageAndExit|();


    2) and validate values second
    3) reconstruct c1 to c5 and asign them to some meaningfull data structure or some class that you use

    Second approach eliminates this high number of params because
    you group them together in pamar4
    but you must use some delimiters and create parses to do it for you.
    Look around you can find argument parsers (JSAP)on Internet
    that could help you with this.

    best of luck!

  3. #3
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    I ecountered similar problem.
    I solved it using a properties file as input.

    you can call your app with
    java -jar app.jar file.prop

    and in the main method you load it
    Java Code:
    Properties prop = new Properties()
    FileInputStream fis = new FileInputStream(args[0]);
    prop.load(fis)
    fis.close()
    And then you have full control over your configuration
    See java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html for more details

  4. #4
    joey86 is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Thumbs up

    ok, thanks man,
    I'll try it out.

    ;)

    Regards,
    Joe

  5. #5
    joey86 is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by FON View Post
    Second approach eliminates this high number of params because
    you group them together in pamar4
    but you must use some delimiters and create parses to do it for you.
    Hey,I had thought of a similar approach like this,

    Java Code:
    java app p1 p2 p3 1,Y,abc,3,N;2,N,def,1,Y;...
    i passed the arguments as above and made my own parser to split the values in the 4th parameter.

    but if there are more values in parameter 4, the command becomes lengthy and hence i was checking for other ways.

    one more constraint in my case is that the parameters are passed from other applications to my app which stops me from using a separate file to store the parameters.

  6. #6
    adz
    adz is offline Member
    Join Date
    Jul 2009
    Posts
    35
    Rep Power
    0

    Default

    No idea if this may be a problem for you but just remember Properties extends hashtable and not LinkedHashMap so it isn't ordered (I wish they'd release a version that was :))

  7. #7
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    @AndreaB

    Andrea I also use Property files for confiiguration,
    but how to you use them
    if user has to enter arguments in command line,
    and has no access to property file
    which may me packed inside of app.jar ?

    please provide us your solution
    thanx in advance

    ragards :)

  8. #8
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    1. its Andre ;-)
    2. Well you can provide a mechanism, where the usre defines his own properties file (arg[0]) and then you can merge it with your own intern file again via the load method (or you manage the input file from user separately ;-)
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  9. #9
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    Thank you Andre!

  10. #10
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

Similar Threads

  1. Command Line Arguments
    By Nakira in forum NetBeans
    Replies: 10
    Last Post: 02-04-2010, 03:45 PM
  2. Command line arguments help
    By may88 in forum New To Java
    Replies: 8
    Last Post: 12-08-2009, 01:20 PM
  3. Multiple Command Line Arguments
    By turnergirl24 in forum New To Java
    Replies: 4
    Last Post: 12-04-2009, 09:36 PM
  4. [SOLVED] command line arguments using IDE
    By sandeepsai39 in forum New To Java
    Replies: 5
    Last Post: 03-12-2009, 07:19 AM
  5. Printing command line arguments
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:27 AM

Tags for this Thread

Posting Permissions

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