Results 1 to 11 of 11
  1. #1
    Vipul03 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Question java command line arguments

    hi

    I want to give command line arguments in java programming as like

    ls -l -a

    for unix system

    My problem is where i want user to give multiple files and give a depth in the given way

    java elecutableClass -d=4 filenames

    to run a program where -d is assigned to a special variable meant for this purpose rather than args.

    For any help thanks in advance

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    You can still parse all those arguments in your main method.

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Try this:

    java -Dd=4 elecutableClass filenames

    In your code, System.getProperty("d") will return the String "4".

  4. #4
    Vipul03 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    Try this:

    java -Dd=4 elecutableClass filenames

    In your code, System.getProperty("d") will return the String "4".
    Thanks for the help but i am still not so clear how to do this

    Can you please give a small example of how to do it.

  5. #5
    Vipul03 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    I tried this code

    1
    2 import java.util.*;
    3 class cmdLineOpt
    4 {
    5 public static void main(String[] args)
    6 {
    7 GetOpt option = new GetOpt(args,"d");
    8 String depth = option.getOptionParam('d');
    9 System.out.println(depth);
    10 }
    11 }

    But the error it is giving is

    cmdLineOpt.java:7: cannot find symbol
    symbol : class GetOpt
    location: class cmdLineOpt
    GetOpt option = new GetOpt(args,"d");
    ^
    cmdLineOpt.java:7: cannot find symbol
    symbol : class GetOpt
    location: class cmdLineOpt
    GetOpt option = new GetOpt(args,"d");
    ^
    2 errors



    Can anyone please tell why is it happening.


    For any help thanks in advance
    Last edited by Vipul03; 02-23-2010 at 07:42 AM.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,441
    Rep Power
    18

    Default

    Where did you get GetOpt from?

  7. #7
    Vipul03 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Where did you get GetOpt from?
    When i searched on google for java getopt, a list of sites including sun's site displayed some examples using it.

    But I am wondering why it is not working in my case.

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,441
    Rep Power
    18

    Default

    It's not part of the SE API as far as I know.

  9. #9
    Vipul03 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    It's not part of the SE API as far as I know.
    Thanks for the help,

    but i still have one confusion, why is it mentioned at below link

    Directory SDK 4.1 for Java API Specification: Class GetOpt


    Thanks once again

  10. #10
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    I don't know why they mentioned it, but notice that the package is:

    netscape.ldap.util

    It is not part of the java API, but is a package from netscape.

  11. #11
    Vipul03 is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

Similar Threads

  1. java command line arguments
    By Vipul03 in forum New To Java
    Replies: 1
    Last Post: 02-22-2010, 02:00 PM
  2. Command Line Arguments
    By Nakira in forum NetBeans
    Replies: 10
    Last Post: 02-04-2010, 03:45 PM
  3. arguments in command-line
    By girlet18 in forum New To Java
    Replies: 2
    Last Post: 01-21-2010, 02:05 PM
  4. Command line arguments help
    By may88 in forum New To Java
    Replies: 8
    Last Post: 12-08-2009, 01:20 PM
  5. Java Command Line Arguments In Eclipse IDE
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-19-2007, 09:45 AM

Posting Permissions

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