How to pass command line options?

I know that command line options contrary to command line data arguments start with a prefix that uniquely identifies them.
I write an application that will copy files from one folder to another. It should be launched with the syntax as follows:
c:>java my.app.DirectoryScannerConsole
c:>scan ?input ?C:/test/in? ?output ?C:/test/out? ?mask ?*test*.xml? ?waitInterval 60000 ? includeSubfolders false ?autoDelete true
c:>exitSo after launching we have two commands: 'scan' and 'exit'. What should I make in my program to be able to invoke these commands in such a manner?
Edited by: Exaserge on Nov 8, 2008 10:38 AM
Edited by: Exaserge on Nov 8, 2008 10:40 AM

Maybe try using Scanner to read in the line of input, then break the line into an String array, then comparing the Strings in the array.
Something like...
public static void main(String args[])
   Scanner in = new Scanner(System.in);
   String line = in.readLine(); //read in an entire line of input
   String words[] = line.split(" "); //split that line wherever there is a space
   while ( !(words[0].equals("exit")) ) //if they haven't typed in exit
      if (words[0].equals("scan")
          if(words[1].equals("-input"))
             String inputFile = words[2]
          //etc.
      line = in.readLine();
      words = line.split(" ");
}I haven't tried to compile it or anything, so it may not be syntactically correct, but you should get the idea.
Edited by: chickenmeister on Nov 8, 2008 1:02 AM

Similar Messages

  • How to pass command-line options to app using the "open" command?

    I am using jedit, and since I'm doing a lot of stuff in a shell, I'd really like to launch it from the command line as though I'd opened from finder, so I wrote a script that contains this:
    open -a /Applications/Jedit.app "$@" &
    This works well for everything except NEW files, where I get this error:
    2007-02-16 19:29:48.072 open[1032] No such file: /Users/millerti/projects/ateon/new_file
    Is there a way I can override this?
    So, it occurred to me that I might try running jedit directly this way:
    /Applications/Jedit.app/Contents/MacOS/jedit -- "$@" &
    The trouble is that this suffers all sorts of weird problems. For instance, if there's already a jedit running, it launches another one (despite the fact that -server is default). Moreover, the file it opens, existing or not, is not the one I specify. If I'm in ~/mydir and I open ./myfile, jedit opens instead /Applications/myfile.
    Obviously, I'm doing something wrong. Can someone help me figure out what open is doing internally so that I can launch jedit compatible with how open does it so that I can both open existing files and create new ones the same way from the command line?
    BTW, I can make more complex script.
    Also, if this isn't the right forum for this, can someone tell me where would be a better place to get the question answered?
    And I'm not expecting to get jedit support here. This isn't a jedit problem because it's behaving correctly.
    Thanks.

    Applications rarely take command line arguments. I don't know anything about Jedit, whether that is an exception, but you are not sending an argument to Jedit with the open command. The file name on your command line is an argument to the open command. The open command says "open this file with the specified application". The application doesn't see the argument. It sees the file exactly as if it were opened from the Finder. That's why naming a non-existent file doesn't work.
    What if you open Jedit with no file, create a new document in the application. (Again, I am not familiar with Jedit.)

  • How to pass command line parameters During server start up

    Hi,
      I am trying to use Net Beans profiling tool.On the server side i required to pass a command line option to enable remote profiling.
    Regards,
    Kiran.

    Hi, MB.
    If you are talking about the automatic Java Web Start support for launching app clients in GlassFish, you can pass the equivalent of command line arguments using the query string of the URL you use to launch the app client.
    Briefly, use
    http://host:port/client-path?arg=first-arg&arg=second-arg& ...
    specifying the argument values in the order that you want them passed to the client.
    The GlassFish server will do the right thing and generates the correct JNLP so your arguments are passed to the app client.
    The GlassFish developer's guide http://glassfish.dev.java.net/nonav/javaee5/docs/AS91DG.pdf discusses this and all aspects of the Java Web Start support. You can also take a look at this blog entry http://blogs.sun.com/quinn/entry/command_line_arguments_and_properties that focuses on how to pass arguments.
    Since this technique deals with argument passing in the URL, it works no matter how you launch the app client: a URL in a browser, the javaws command, etc.
    - Tim

  • How to pass command line arguments to JWS app

    Hi,
    I want to pass command line arguments to my JWS application. However those arguments are dynamic (eg the username of the user who launched the app) and thus I can not use the argument tag of JNLP file. So what do I need to do in this case?
    Thanks.

    Well, if it's the username on your server systems you should probably include it in the jnlp: can pass it in the url, write once and remove jnlp href attribute, etc.., etc.. (a quick tour of this forum should suffice).
    If it's the OS username you should be able to retrieve it through system properties.
    Whatever it is, passing dynamic arguments means launching javaws through a shell or a shell script (bat if running on windows), so you won't be able to launch through autogenerated desktop and menu shortcuts.
    Anyway, you have two solutions:
    Clean one: associate an extension to your app and write those infos in a file named after that extension.
    Dirty one (always seen it work, but there's no warranty): javaws -open whateverParamYouLike yourAppURL.jnlp, will pass to your main method '-open' as args[0] and '+whateverParamYouLike+' as args[1]. I gotta admin I used it, but I had the most peculiar reason (my app needed another instance on a different JRE aware of being a secondary instance at startup time).
    Bye.
    PS: I'd really love dukes ;-)

  • How to pass command line parameters in calling ant file

    Hi All, I m using a Build file which calls another build file.
    That build file is run from the command prompt by give ant -lib <path of jars it needs for executing>.
    Now i m calling this file from main build file but it does not work as i m not able to set <b>-lib </b>.
    Pls can anybody let me know how to set such command line parameters to call the build file in ant script.
    Thanks in Advance.
    Ketan.B.Parekh

    Create the control file dynamically (and fill one of the columns with the file name as a constant) before you start SQL*Loader
    Another option is to use external tables
    Re: Data Loading
    Message was edited by:
    Jens Petersen

  • How to Pass Command line arguments to an exe created in LV8.0

    Hi Friends,
    I have Created an exe in LV8.0, which accepts the Folder path as input and executes.
    I want to call this exe passing the parameter (i.e folder path in my case)  from the command line argument. How to pass arguments to the exe ?
    Generally we may be having different types of input parameters to a vi like numeric control, string, boolean etc..If we create an exe that needs three input parameters among which one is boolean, other is string and third is a numeric value.
    How to pass these different types of input controls to the exe as parameters in command line at the same time?
    Thanks and Regards,
    SODLB

    I don't have any experience with the 8.x application builder, but the 7.x one has a checkbox for passing the arguments to the executable.
    As for reading them, there should be an example in the example finder (Help>>Find Examples) which shows how to do this. If you want to pass multiple parameters, I suggest you use a structure similar to NAME=VALUE, so that you can parse each element to find the = and then use a case structure to decide what to do with the parameters. This allows your users to enter or not enter any of the switches.
    Try to take over the world!

  • How to pass command line arguments to Web Start appclient?

    Hi,
    I would like to pass arguments to appclient, but "javaws" unable to do that.
    Do I have to overwrite the JNLP? I use Sun Appserver 9.0, it creates JNLP on the fly!!!
    Please help, thanx!
    MB

    Hi, MB.
    If you are talking about the automatic Java Web Start support for launching app clients in GlassFish, you can pass the equivalent of command line arguments using the query string of the URL you use to launch the app client.
    Briefly, use
    http://host:port/client-path?arg=first-arg&arg=second-arg& ...
    specifying the argument values in the order that you want them passed to the client.
    The GlassFish server will do the right thing and generates the correct JNLP so your arguments are passed to the app client.
    The GlassFish developer's guide http://glassfish.dev.java.net/nonav/javaee5/docs/AS91DG.pdf discusses this and all aspects of the Java Web Start support. You can also take a look at this blog entry http://blogs.sun.com/quinn/entry/command_line_arguments_and_properties that focuses on how to pass arguments.
    Since this technique deals with argument passing in the URL, it works no matter how you launch the app client: a URL in a browser, the javaws command, etc.
    - Tim

  • How to process command line options with plugin?

    Hi there,
    i am currently working on a c++ plugin for Adobe Acrobat 7 with the SDK 7.0.5.
    I let the user open a specific pdf by clicking a link in the browser,
    therefor I registered an additional protocol in the windows registry. Works fine.
    But I now want to tell my plugin some specific things when calling acrobat.exe that way.
    So is there a way to get self-specified command line parameters given to acrobat.exe?
    It would also be helpful if my plugin would know the URL parameters appended with #.
    I could also use that.
    I could not find anything on that issue.
    kind regards,
    Sebastian

    No, your plugin doesn't get any access to the command line.  Look for other methods of IAC (COM, DDE, shared memory, shared file, etc.)

  • Javadoc command line options

    I have a custom doclet which generates xml output instead of the default ouput from javadoc.
    I am trying to pass custom command line options to my custom doclet class.
    The following is my javadoc command:
    javadoc -classpath c:\junit\junit3.8.1\junit.jar;C:\j2sdk1.4.1\lib\tools.jar -doclet DocGenerator -dest c:\docgen\temp C:\DocGeneratorTest.java
    When i use the above command i get the following error:
    javadoc: invalid flag: -dest
    I am trying to access the value of dest in my custom doclet.
    Regards
    -rv

    Perhaps the following will help. It explains how to use command-line options
    Any doclet that uses custom options must have a method called
    optionLength(String option) that returns an int. For each custom
    option that you want your doclet to recognize, optionLength must
    return the number of separate pieces or tokens in the option. This page gives an example:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/javadoc/overview.html#options
    -Doug Kramer
    Javadoc team

  • How do I restart the SNMP agents with the original command line options?

    I'm creating an application that changes the SNMP trap target configuration files and then restarts the SNMP agent. I'm currently working with the mibiisa agent. I want to make sure that I restart the service with the new trap targets but with the original command line options. How can I restart the mibiisa service with the same command line options that it originally loaded with?

    It is not "Network Time" that is the problem, but actually "SystemStarter." SystemStarter is an interim kludge to enable the work or the old StartupItems until they can be converted to LaunchDaemons or LaunchAgents controlled by launchd. Launcd calls SystemStarter to launch all the unconverted StartupItems. ntpd is now under the control of launchd directly.
    Launchctl is the command to load and unload the plist files, but I don't think it has a mechanism to restart a daemon.
    There are start and stop commands in launchctl, but the man page indicates that they are for debugging purposes.
    I also imagine you could just kill the ntp daemon and let it restart with new settings. It is most likely set to "keepAlive" so that it will automatically restart.

  • Command line options in executable jar

    Hello,
    On a win32 system I have an executable jar that the user dbl clicks to run.
    What I would like to do is maintain this simple dbl click to run but have command line options passed to the vm. ie I would like the dbl click to invoke
    javaw -Xms60m -Xmx120m -jar myjarfile.jar
    rather than just
    javaw -jar myjarfile.jar
    Can these options be placed in the jar files manifest? If so how? (I can't see how to do it)
    Many thanks
    Mike

    why not use special .jar tool to help you to save much
    of your time?
    Thanks for the idea but it really doesn't answer my question.
    Mike
    [Edited by: jdcforumadmin1 on Jun 24, 2002 1:39 PM]

  • 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/

  • Command line option to specify Bridge master cache

    Please allow a bridge command line option to allow the user to select a specific bridge master cache.
    The  motivation is as follows:  I have written a c++ programme to key-word  all of my many thousands of photo projects.  Essentially each project is  in a separate directory on 8 terabytes of networked disk.  Associated  with each directory is a set of key words.  When the appropriate project  is selected, I invoke Bridge to open that directory, possibly with a  specific images as the "starting image" for that project.  Since the  master cache files are split (to accomodate the 500,000 max image count  supported by bridge), it would be excellent if I can pass a reference to  the specific master cache associated with that directory.
    A second value of this option would allow the user to create desk-top short-cuts to invoke bridge using an appropriate cache structure.  For example, the properties of one short cut could specify the cache file for the current daily use of the Bridge to process images in progress.  A second could point the the cache associated with the historical first 400,000 image archived on the network, and a third could invoke bridge pointing to the cache for the next 400,000 image cache - or whatever grouping the user needs to match his workflow when using Bridge as the central focus for various digital assets..
    This type of processing allows the user to conveniently invoke bridge according the the needed work flow when multiple cache systems are required.  In addition, the multiple desk-top shortcuts would minimize the "error" of having bridge pointed, by accident/neglect, to the incorrect cache structure.
    It would also be valuable to allow the user to display the current number of actual image items in a cache system - either as a "view" or "tools" option.  This would allow the user to know when it is time to start a new master cache system. Of course, this can be intependently viewed in windows explorer by the count of files in the 1024 or 256 directories - however maybe the cache structure already "knows" this number instantly.  Other statistics could be interesting as well - possibly the number of directories known to the cache (possibly the same as the count of directories within the 1024 or 256 directories). Possibly the number of files cached by file type (jpg, tif, psd, cr2, nef, etc) would be of interest to some folks - however, such things should be user-selectable since such analysis might be time intensive and maybe of no interest.
    Of course, I do not know if this is consistent with other uses of Bridge - this request is made based upon my use of Bridge as a still photographer and a few videos I have created.
    thank you....
    tony

    I'm going to be technical for a minute, just for the Forum archives...
    The Library file location is stored in your "iTunes Prefs.xml" file in<pre>%APPDATA%Apple ComputeriTunes</pre>.
    Actually, I should say that if you are using a non-default location, there is a key for "iTunes Library Location:1", e.g.:
    <key>iTunes Library Location:1</key>
    <data>
    QwA6AFwARABvAGMAdQBtAGUAbgB0AHMAIABhAG4AZAAgAFMAZQB0AHQAaQBu
    AGcAcwBcAFQAZQByAGkAZABvAG4AXABNAHkAIABEAG8AYwB1AG0AZQBuAHQA
    cwBcAE0AeQAgAE0AdQBzAGkAYwBcAHQAZQBzAHQAbABpAGIAcgBhAHIAeQA=
    </data>
    The "data" is a base64-encoded UTF16-LE string that is the folder containing the "iTunes Library.itl" file and "Album Artwork" folder. In the above case:<pre>C:Documents and SettingsTeridonMy DocumentsMy Music     estlibrary</pre>
    The key/data pair does not exist if you're using the default Library location.
    Similary, there is a key/value pair for "iTunes Library XML Location:1" -- except this part always appears, even if you are using the default location. Also, it is the full path to the file itself, not just the directory containing it. e.g.:<pre>C:Documents and SettingsTeridonMy DocumentsMy Music     estlibraryiTunes Library.xml</pre>
    Since it doesn't appear that double-clicking on the Library file you want to open works, I'm guessing the only way to swap locations is to edit the preferences file -- either directly, or with a script/program. I could probably write such a program in a 1/2 hour or so... I might just do that right now.

  • 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

  • Passing command line unicode argument to Java code

    I have to pass command line argument which is Japanese to Java main method. If I type Unicode characters on command-line window, it displays '?????' which is OK, but the value passed to java program is also '?????'. How do I get the correct value of argument passed by the command window? Below is sample program which writes to a file the value supplied by command line argument.
    public static void main(String[] args) {
    String input = args[0];
    try {
    String filePath = "C:/Temp/abc.txt";
    File file = new File(filePath);
    OutputStream out = new FileOutputStream(file);
    byte buf[] = new byte[1024];
    int len;
    InputStream is = new ByteArrayInputStream(input.getBytes());
    while ((len = is.read(buf)) > 0) {
    out.write(buf, 0, len);
    out.close();
    is.close();
    } catch (Exception e) {
    e.printStackTrace();
    }

    To clarify a little:
    If the "command line" means a console opened from the operating system, then the problem is that your machine's operating system can't handle the Unicode characters you want (at least, not in the console mode). If you can't configure the machine to accept Unicode on the command line, you'll have to investigate some other means of passing the argument to your app, as the other poster mentioned.

Maybe you are looking for