Setting Command Line Arguments for my Class

HI,
How do I set the command line arguments for my debug class. For example , I would like my user to type :
java Debug -LEVEL1
What should I do to implement this behaviour.
Thanks in advance...

     public static void main (String[] args){
          if(args.length > 0){
               int j = 0;
               BMsearch search = new BMsearch();
               try{
                    while (j < args.length){
                         if(args[j].equalsIgnoreCase(ONE_PATERN)){
                              search.addPaternForSearch(args[j+1]);
                              j = j+2;
                         else if (args[j].equalsIgnoreCase(PATERNLIST)){
                              j++;
                              while( ! (args[j].startsWith("-")) ){
                                   search.addPaternForSearch(args[j]);
                                   j++;
                              }//end while
                         else if (args[j].equalsIgnoreCase(PATERNFILE)){
                              j++;
                              search.readPaternFile(args[j]);
                              j++;
                         else if(args[j].equalsIgnoreCase(MATCH_H)){
                              search.heuristic = MATCH_HEURISTIC;
                              j++;
                         else if(args[j].equalsIgnoreCase(MATCH_H2)){
                              search.heuristic = MATCH_HEURISTIC_TWO;
                              j++;
                         else if(args[j].equalsIgnoreCase(OCC_H)){
                              search.heuristic = OCC_HEURISTIC;
                              j++;
                         else if(args[j].equalsIgnoreCase(COMB_H)){
                              search.heuristic = COMBINED_HEURISTIC;
                              j++;
                         else if(args[j].equalsIgnoreCase(JAVA_S)){
                              search.heuristic = JAVA_NATIVE;
                              j++;
                         else if(args[j].equalsIgnoreCase(TEXTFILE)){
                              j++;
                              search.readFileIn(args[j]);
                              j++;
                         else if(args[j].equalsIgnoreCase(TEXTURL)){
                              j++;
                              search.readURLFileIn(args[j]);
                              j++;
                         else if(args[j].equalsIgnoreCase(STOPatFIRST)){
                              search.searchall = false;
                              j++;
                         else if(args[j].equalsIgnoreCase(STOPatLAST)){
                              search.searchall = true;
                              j++;
                         else if(args[j].equalsIgnoreCase(VERBOSE)){
                              search.verbose = true;
                              j++;
                         else if(args[j].equalsIgnoreCase("-h") || args[j].equalsIgnoreCase("-help")){
                              printHelp();
                              Start = false;
                              break;
                         else{
                              System.out.println(" Error while parsing Parameter. ");
                              System.out.println(" type java BMsearch -help for all Options");
                              Start = false;
                              break;
                    }// end outer while
               catch(Exception e){
                    System.out.println(" Error while parsing Parameter. ");
                    System.out.println(" type java BMsearch -help for all Options");
                    Start = false;
                    j = args.length;
               if(Start){
                    if(search.verbose)System.out.println(" Parameter parsed, beginning with search ...");
                         search.starttimeTotal = System.currentTimeMillis();
                    search.search();
                    search.stoptimeTotal = System.currentTimeMillis();
                    System.out.println(" Whole search took:  " + (search.stoptimeTotal - search.starttimeTotal) + " milliseconds.(Brutto) ");
          else{
               System.out.println(" Error while parsing Parameter. ");
               System.out.println(" type java BMsearch -help for all Options");
     }//end MAINThis is takem from one of my command line classe (a Boyer Moore Pattern-Matching application from an exercise). I don't know if this is the best way, but thats what I have done there for passing some arguments, where the order of them isn't pre-given (you can pass the params in the order you want).
The CAPITAL vars are pre-defined final Strings holding the param-names, e.g.
public static final String ONE_PATERN = "-p";
public static final String PATERNLIST = "-plist";
public static final String PATERNFILE = "-pfile";Another trick sometimes used in Linux/Unix, if you have only false/true combinations, are numbers from pow 2 (2,4,8,16). In C they are used because of the binary representation, but it has some benefits. E.g. a value of 2 (0010) and another true set on 4 (0100) results binary in 6 (0110), so you can mix parameters in only one value, and with a byte - array you could check, if the flag for a given param is set. But this way is a little tricky for the end-user.

Similar Messages

  • Need Help with command line arguments for a class method

    Hey guys,
    I'm fairly new to programming in java.
    I want to a write a class method that adds up its command line arguments which are numbers. For example, if the input was .... 5 2 3....then the output would be 10.
    I have been told to use the Convert to convert a string to a double. I'm ok for writing the class method but I have no idea how to use Convert and why I need it in the method.
    Can anybody help please?

    Hey guys,
    I'm fairly new to programming in java.
    I want to a write a class method that adds up its
    command line arguments which are numbers. For
    example, if the input was .... 5 2 3....then the
    output would be 10.Okay. So you would receive the numbers to add as the String[] argument to a main method. The steps are simple:
    1) declare a variable for the count
    2) for each String in the array:
    2.1) extract the value as a double
    2.2) add this to the count
    3) output the resulting count
    I have been told to use the Convert to convert a
    string to a double.
    I'm ok for writing the class
    method but I have no idea how to use ConvertThere is no class Convert in the Java API.
    and why
    I need it in the method. Do you understand you need to somehow convert each String to a double (step 2.1)? Since Convert is unknown to me, maybe you should just take a look at class Double. It can help you do step 2.1, the rest should be trivial enough.
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Double.html
    Give it a go and feel free to post back with a specific problem you are having, accurately described if you please :-)

  • Burrito - can't set 'command line arguments' (mobile)

    Hi all,
    The option to set command line arguments in the "Run/Debug Settings" - "Launch Configurations" dialog disappears when a new "Flex Mobile AIR Project" is created.
    I am developing APKs that are launched via Intents from other Android apps; setting arguments for testing in the IDE would improve the workflow that now requires me to deploy to the device for testing. Is there a workaround for this?
    Thanks,

    Put the command into a file with execute permissions, including whatever command-line arguments you want. For instance, the file might contain the following:
    #! /bin/bash
    xpdf -g 1200x900 -z width -cont "$1"
    In Firefox preferences, under "Applications," locate the appropriate Content Type and in the Action menu, select "Use other..." and then locate the executable file you just created and select it.
    In UNIX-type operating systems at least, available options to the command can be found using the "man" command (e.g. "man xpdf" for the example above).

  • Command Line Arguments for file i/o

    I am giving the following two command lines:
    C:\mydir> java store item.txt me.rep -first
    C:\mydir>java store item.txt me.rep -second
    What do these lines really mean? I can tell that it is given two options to the user

    keek,
    Traditionally On Unix command line switches are prefixed with a dash.
    For example:
    \rm -r -f * .*(Do NOT try this to find out what it does, unless you're using your ex-wives computer, in which case don't forget to cd / first.)
    For the second and final time: We have no way knowing what the "first" or "second" switches of some arbitrary "store" class signify... you'r either going to have to work it our for yourself or provide a LOT more information... like the source code for the "store" class.
    Keith.

  • Looking for pfi command line arguments.

    Hey,
    I've read through all documentation but can't find a list of all available command line arguments for pfi. the pfi -help does not list any options for me. Does anyone have a link to a list or is there some way to get the -help argument to output the list?
    Thanks,
    Jonas

    Below mentioned pdf has some info on the command line args of pfi under the heading Creating an iPhone application installer file from the command line
    http://download.macromedia.com/pub/labs/packagerforiphone/packagerforiphone_devguide.pdf
    Tanu

  • Obtaining command line arguments

    Can someone point me at an example of how to obtain command
    line arguments from inside my Flex application? I want to have my
    Flex application perform different tasks when it is launched with
    different command line arguments, for example:
    myApp.exe 1
    myApp.exe 2
    myApp.exe 3
    How is that done in a Flex app?
    TIA,
    Steve

    "plug_in_guy" <[email protected]> wrote in
    message
    news:gnfgf2$ir1$[email protected]..
    > Can someone point me at an example of how to obtain
    command line arguments
    > from
    > inside my Flex application? I want to have my Flex
    application perform
    > different tasks when it is launched with different
    command line arguments,
    > for
    > example:
    >
    > myApp.exe 1
    > myApp.exe 2
    > myApp.exe 3
    >
    > How is that done in a Flex app?
    This may help:
    http://www.davidtucker.net/2008/01/23/air-tip-7-using-command-line-arguments/

  • Solaris 10 command-line argument to /etc/init.d/apache

    Does anyone know how to control the command-line argument sent to /etc/init.d/apache that ships with Solaris 10 11/06?
    # svcs *\apache\*
    shows Solaris is running Apache 1.3 as a legacy service with the FMRI lrc:/etc/rc3_d/S50apache.
    According to Sun documenation ("How to Modify a Command-Line Argument for an inetd Controlled Service" <http://docs.sun.com/app/docs/doc/817-1985/6mhm8o5ss?a=view>), one should be able to make desired changes using the inetadm command. The problem is,
    # inetadm
    doesn't show anything at all related to apache or httpd. I thought about changing the inittab file, but Sun's comments in the file pretty much say "hands off."
    I'm trying to have Apache SSL enabled at boot time (i.e. argument startssl instead of start). As a temporary hack, I've edited apachectl so that the "start" argument is processed like "startssl."
    Thanks!

    tmilbank wrote:
    Does anyone know how to control the command-line argument sent to /etc/init.d/apache that ships with Solaris 10 11/06?
    # svcs *\apache\*
    shows Solaris is running Apache 1.3 as a legacy service with the FMRI lrc:/etc/rc3_d/S50apache.
    According to Sun documenation ("How to Modify a Command-Line Argument for an inetd Controlled Service" /etc/rc3 services have nothing to do with inetd.
    The script is running from the above file (/etc/rc3.d/S50apache).
    That's normally apache 1.x. If you do 'svcs -a', you'll see disabled services as well, which will include the apache 2.x server.
    <http://docs.sun.com/app/docs/doc/817-1985/6mhm8o5ss?a=view>), one should be able to make desired changes using the inetadm command. The problem is,
    Neither version of apache runs from inetd. Are you interested in apache 1.x or apache 2.x?
    Darren

  • Class to parse command line arguments.

    Hi,
    Is there a Class to parse the Command line arguments of a program?
    Perhaps something like Getopt in perl.
    Thanks,
    Anupam.

    I'm not sure if this is what you're asking, but it does it for you already. The args[] array in the main method holds the command line arguments parsed with space delimiters. So if on the command line you put:
    java MyClass these are arguments
    The args array would contain:
    args[0] = "these"
    args[1] = "are"
    args[2] = "arguments"

  • DP Execution-Execute a DP without supplying value for command line argument

    DP Execution - How to execute a DP without supplying value for a command line argument?
    My requirement is like Directive should have an optional command line argument.
    i.e., even if the value is not supplied for the command line arg, my DP should run.
    Your help is appreciable.

    What is DP?
    What is Directive?

  • How to run command line argument programe

    Hi guys, I am doing pass command line argument programe in java but I don't know how to run this programe. Path for this programe in my my computer is C:\Users\Desktop\Mainjava\mycode\CommandProgjava*
    {code/}
    public class CommandProg
    public static void main(String[] args)
    System.out.println("d");
    for (int i = 0; i < args.length; i++)
    System.out.println(args);
    {code/}
    Where i need to go and what command i need to give so i can execute this programe(I am using window vista). I only know i have to give
    this command some where CommandProg arg1 arg2 arg3 arg4. Output should be
    Output:
    arg1
    arg2
    arg3
    arg4
    Please help me, Thanks in advance.
    Edited by: JayVirk on Dec 30, 2007 11:33 AM

    Jay,
    Your question isn't very clear, hence Joerg's well meaning but irrelevant advise.
    Do you mean:
    I've written a simple program in java which echos
    it's command-line arguments to back to the console.
    Here's my code:
    package forums;
    public class ArgsEchoer
      public static void main(String[] args) {
        for (String arg : args) {
          System.out.println(arg);
    But can't figure out how to compile and run the program.
    I'm using winblows shista, and it's cr@p.
    Please help me, Thanks in advance.So... where are you at? Have you installed the JDK (java development kit)? Which version? Is your path set? Is your classpath set?
    Start here: http://java.sun.com/developer/onlineTraining/new2java/

  • Documenting command line arguments

    I'm very new to javadoc, and I'm trying to put together a set of guidelines for our developers to follow. One thing I came accross was command line arguments. If a main function is expecting command line arguments, how would this be documented, should @param be used? I didn't see anything about this in the guidelines sun has posted. Any help is greatly appreciated.

    This is my own personal opinion, so don't treat it as a "fact", but I don't think Javadoc is best suited for specifying command line arguments. You could do the following:
    *  Description of main() here...
    * @param args First parameter = xxx, Second parameter = yyy;
    public static void main(String[] args)
    }In this way you can specify all command-line parameters that are required in order to make the appliction run.
    BUT...
    Javadoc is meant more to be a programmatic guide to how to allow Java classes to interoperate. Java classes (mostly) will not care at all what the command-line parameters to the main invocation are. That is information that is only really needed to be known by the application executor at runtime.
    Therefore, for all my apps, I do the following to comment what types of parameters should be passed to the invocation of the application:
    * My App comments...
    * @param args Run application without any parameters to see list of all necessary command-line parameters.
    public static void main(String[] args)
       if (args.length < 1)
          System.out.println("This application allows the following parameters:");
          System.out.println("   Param#1 = xxx, <description>");
          System.out.println("   Param#2 = yyy, <description>");
          System.exit(0);
    }In this way, you do not clutter up the Javadoc APIs (used for classwise interaction) with command-line parameters, but the command-line parameters are still specified by "documentation" (running the application without any parameters).
    If parameters are optional, instead of mandatory, you could do something similar...
    * Documentation...
    * @param args Run -h as first flag for list of all optional parameters.
    public static void main(String[] args)
       if ((args.length > 0) && (args[0].equals("-h"))
          // Print out all possible parameters.
    }Anyway, this system has held me in good stead for the last couple of years.

  • How to hide the command line arguments from solaris process

    Hi All,
    When I execute a JAR application from a java file using the Runtime.getRuntime, the command line arguments (user ID and Password details) which I passed for executing the application displayed on Solaris process (ps -ef).
    Could anybody please help me, how can I hide either the process or the command line arguments from the Solaris process?
    I cannot pass any asterix or any special character in place of password, because the executing application doesn't have any functionality to retreive the password which send as asterix characters.
    Please help me
    SumodeV

    Thanks for all the response.
    I have created a design and implement the functionality which executes the JAR application in Solaris environment without showing any details in the process details.
    I have used the Java Reflection method, which invokes the JAR application. I am sharing the details here for all those who looking for it.
    1, Inside the Customer application [Jar File is running for it], collect the necessary session details [Using System.get property method]
    2, Create an independent Java file, which should be used to invoke the JAR application
    3, Create the ProcessBuilder object and use a command - execute the Java file [a wrapper code] using normal Java command
    4, Pass the necessary session details to the ProcessBuilder using the environment() function.
    5. Collect the environment values in the independent Java file (Which was invoked by ProcessBuilder) and set details for its environment using System.setProperty.
    6, Use reflection technique to invoke the JAR plugin [which you want to run]. You can use the standard Java functionality to read the MANIFEST file of JAR and load the main class using URLClassLoader.
    7, Invoke the main method of the JAR file, which run the JAR application in Solaris window
    This solution will make sure that the process cannot display any session details in the Solaris Environment.
    Note: Use String[] array while create the command. Otherwise the JAR application cannot pop-up.
    Regards
    Sumode

  • Sending varargs via command line arguments to main()

    When I put A B C D in the command line arguments textbox in my compiler, the output is as expected: A B C D. However, when I put *new String[]{A, B, C, D}*, the output is *new String[]{A, B, C, D}*, not A B C D as I had expected. My code is below. Any suggestions?
    package varargs;
    public class Varargs {
        static void printArray(Object...args){
            for (Object obj : args)
                System.out.print(obj + " ");
            System.out.println();
        public static void main(String...args) {
            printArray((Object[])args);
    }

    The argument(s) that is/are supplied to your main method will be rendered as literal String constants. It looks like you are attempting to use java code as one of your arguments with the expectation that the program will interpret this code. It won't. Your program will simply display whatever it is given even if what you offer as an argument happens to be a construct of the Java language.

  • Sending Command Line Arguments to Jar Executable

    Hi All
    I wish to send Command Line Arguments to Jar Executable.
    i.e. before I Jar'd my program, I would do the following
    public class CmdLnArgmntExp {
    public static void main(String[] args) {
    System.out.println("d");
    for (int i = 0; i < args.length; i++)
    System.out.println(args);
    Running the program in Console.
    Java CmdLnArgmntExp arg1 arg2 arg3 arg4Output:
    arg1
    arg2
    arg3
    arg4
    How would I do this to a Jar executable, hope that made sense
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    java -jar executable-jar-file-containing-class-CmdLnArgmntExp.jar arg1 arg2 arg3 arg4

  • File name as command line option for multiple VM processes

    "-Xloggc:/tmp/gc.log" is the option I'd like to set, but every process will log to that file and even if we don't experience any concurrency issues the data still isn't useful because I can't tell which process did what.
    The island files are cleverly named to include their process number, can I do similar for command line options or will I be restricted to a single JVM?

    Online help (as of LabVIEW 7.0?), Index, Command Line, User-defined arguments - It will show you the following:
    You also can pass LabVIEW-defined or user-defined arguments when you launch LabVIEW from the command line. To pass user-defined arguments in the command line, enter two hyphens (--) surrounded by spaces before the set of user-defined arguments. LabVIEW does not use any arguments after the two hyphens to launch labview.exe. LabVIEW passes the arguments after the two hyphens to the block diagram of the VI you launch. Use the Application:Command Line Arguments property to read the user-defined command-line arguments passed when LabVIEW launches.
    For example, to launch mycool.vi and pass user-defined arguments, use the following command:
    c:\labview\la
    bview.exe c:\coolapp\mycool.vi -- 1000 sine
    On the block diagram of the mycool.vi, use the Application:Command Line Arguments property to read the 1000 and sine arguments you passed and handle the values.
    Enjoy,
    Roy

Maybe you are looking for