System date as Command line argument

Hi
Can we pass system date as commandline argument to a java program.
If yes,How?
thnx in advance

A simple work-around:
public class Test {
     public static void main(String[] argv) {
          if (argv.length != 0) {
               if (argv[0].equalsIgnoreCase("date")) argv[0] = new java.util.Date().toString();
               System.out.println(argv[0]);
}

Similar Messages

  • Charset encoding of command-line arguments

    I have a java application which accepts a string from command line arguments like this
    java myapp <arguments>What will be the charset encoding of the arguments? It may contain some foreign characters.
    The default charset encoding of my JVM?? is windows-31j.
    System.out.println(Charset.defaultCharset().name());
    // output: windows-31jI need to convert the arguments into bytes array but i don't know what charset to specify in arguments.getBytes()?
    Please help.

    Kyowa wrote:
    I need to convert the arguments into bytes array but i don't know what charset to specify in arguments.getBytes()?
    Please help.The arguments are presented as String data, which should always be in UNICODE, regardless of the encoding used by the platform. There could be problems with conflict between the command line shell and the JVM with non-Latin characters, which would be a matter of configuration, but the string you get should be UNICODE.
    When you chose to convert a UNICODE string to a byte array or stream then you use whatever encoding you want the bytes to be in. In the Java model, it's characters stored as bytes which are encoded in various ways. The encoding encodes to and from the UNICODE characters used in Strings.

  • Error while running aiaconfig.sh - The command line argument(s) "weblogicConfig"

    Hi.
    We are Configuring PIP on AIA 11.1.1.7 after installing AIA PIP release. we we run ./aiaconfig.sh we are getting below error message,
    $./aiaconfig.sh
    Starting Oracle Universal Installer...
    Checking swap space: must be greater than 500 MB.   Actual 169130 MB    Passed
    Checking monitor: must be configured to display at least 256 colors.    Actual 16777216    Passed
    Preparing to launch Oracle Universal Installer from /tmp/OraInstall2013-11-20_04-11-10AM. Please wait ...adevaia                                                        @soa-odi-dev1:/u02/app/Oracle/Middleware/AIAHOME/bin$ [WARN ][jrockit] MaxPermSize=256m ignored: Not a valid opt                                                        ion for JRockit
    Log: /u01/app/oraInventory/logs/install2013-11-20_04-11-10AM.log
    The command line argument(s) "weblogicConfig" or the install mode specified is not valid.
    Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
    Usage:
    config.sh [-mode] [-options] [(<CommandLineVariable=Value>)*]
    Where mode include:
    [Mode is a mandatory parameter. Only one mode can be specified.]
         -silent For silent mode operations, the inputs can be a response file or a list of
                  command line variable value pairs.
    Where options include:
         -help, --help, --usage
                  Displays above usage.
         -invPtrLoc <inventory pointer file>
                  Launches the installer with a custom inventory location. The invPtrLoc
                  should point to a file which contains the following information.
                  inventory_loc=<inventory_location>
                  inst_group=<group_name>
         -response, -responseFile <response file>
                  Specifies the response file and path to use.
         -jreLoc <location>
                  Path where Java Runtime Environment is installed. OUI cannot be run without
                  it.
         -logLevel <level>
                  To filter log messages that have a lesser priority level than <level>.
                  Valid options are: severe, warning, info, config, fine, finer, finest,
                  basic, general, detailed, trace. The use of basic, general, detailed, trace
                  is deprecated.
         -debug  For getting the debug information from OUI.
         -force  Allowing silent mode installation into a non-empty directory.
         -printdiskusage
                  Log debug information for disk usage.
         -printmemory
                  Path where Java Runtime Environment is installed. OUI cannot be run without
                  it.
         -printtime
                  Log debug information for time usage.
         -waitforcompletion
                  For windows. setup.exe will wait for completion instead of spawning the
                  java engine and exiting.
         -noconsole
                  For suppressing display of messages to console. Console is not allocated.
         -ignoreSysPrereqs
                  For ignoring the results of the system pre-requisite checks.
         -executeSysPrereqs
                  Execute system pre-requisite checks and exit.
         -paramFile <location of file>
                  Specify location of oraparam.ini file to be used by OUI.
         -novalidation
                  Disables the validations, can be invoked along with GUI or silent mode.
         -nodefaultinput
                  Disables the default computation of values (pre-populating of values when
                  screen is loaded) in GUI install.
         -nocheckForUpdates
                  To disable all updates checking
         -updatesDir
                  To specify the directory where latest updates are downloaded. This could be
                  used in disconnected mode.
    Command Line Variables Usage:
              Command line variables are specified using <name=value>; for example:
                  [ session: | session:compName: | session:compName:version: ]variableName=" valueOfVariable"]
              Installer variables are specified using:
                  varName=value
                  Ex: ORACLE_HOME=<value>
              OUI Session variables are specified using:
                  session:varName=value
                  Ex: session:VARIABLE_NAME=<value>
              OUI Component variables are specified using:
                  session:compInternalName:[Version:]varName
                  Ex 1: session:oracle.comp1:1.0.1:varName=<value>
                  Ex 2: session:oracle.comp1:varName=<value>
                  The lookup order is compInternalName:Version:varName, then compInternalName:varName
    do anyone had any idea on this.
    Thanks a lot,
    RR.

    try checking relevant environment variables like the CLASSPATH.... a major source of failures in Windows is when in the classpath there is a path containing SPACES.... also enabling some "debug" or "verbose" flag (not sure how to do it) would provide more insight...

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

  • 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

  • How to add command line arguments to shortcuts in the LV8.5.1 installer

    I want to create multiple shortcuts to my LV program, each with different command line arguments.
    I can do this manually.
    I want the installer to generate these shortcuts.
    I can add different shortcuts in de installer build specification, but I cannot add commandline arguments in the shortcuts.
    Does anyone know how to do this?
    Rindert 

    Hello Forum,
    Does anyone have any better data for this?  I would also like to create an installer using Labview Project Explorer tool (Build Specification->Installer), and I have a need to create some shortcuts to some EXE's (VS.NET built, not LV) which need to have some arguments passed.  I just verified that LV8.6 still does not seem to offer the option of passing arguments when creating shortcuts.  Is this correct?   Creating stub EXE's or batch files isn't a good option for my project, so I'd like to have someone confirm if LV installer tool can't create shortcuts w/ arguments before I fire up InstallShield.
    Regards!

  • Read in file name + path using command line arguments

    Hi guys,
    I am trying to use command line arguments to read in the name of two files. The code below works as long as the files are on the class path.
    public class cmdLineArguments {
         public static void main(String[] args) {
              String xmlFile1 = args[0];
                    String xmlFile2 = args[1];
              System.out.println ("\nXmlFile1: " + args[0] + "\nXmlFile2: " + args[1]);
    }I would like to be able to read files that are not on the class path as well by entering their full path along with their names.
    In other words, It works if I type:
    C:\Documents and Settings\user\workspace\CmdLineArgs\src>java cmdLineArgs file1.xml file2.xmlbut not if I type:
    C:\Documents and Settings\user\workspace\CmdLineArgs\src>java cmdLineArgs c:\Documents and Settings\user\desktop\file1.xml c:\Documents and Settings\user\desktop\file2.xmlWould anyone please explain how I can edit the code to make it work? I guess I could take them both as a String, modify them manually (add a \ to it etc) but is there an easier way to do it? Even a reference to a tutorial, article etc about this would be very much appreciated.
    Also, any idea why a code would compile and run fine in Eclipse but would create an error from command line?
    Thanks a lot.

    You need to learn about cmd.exe which is used to process the command line. The arguments passed to any program is the command line split at white space so your command line arguments of
    c:\Documents and Settings\user\desktop\file1.xml c:\Documents and Settings\user\desktop\file2.xmlis turned into an array of
    "c:\Documents", "and", "Settings\user\desktop\file1.xml", "c:\Documents", "and", "Settings\user\desktop\file2.xml"In other words instead of 2 arguments you actually have 6.
    To get round this the file names need to be quoted
    java cmdLineArgs "c:\Documents and Settings\user\desktop\file1.xml" "c:\Documents and Settings\user\desktop\file2.xml"

  • Executing another program with command line arguments

    I am very new to Java, so bare with me.
    I have written an encryption/decryption program in C (that accepts command line arguments of the key, mode (encrypt/decrypt), and file), and I have written a GUI for it in Java. It accepts the filename (and has a button which opens the "File/Open" dialog), key, and mode, and has a button to Start the process of the encryption. I'd like for that "Start" button to call my encryption program in C (eep.exe) with the command line arguments of the file, key, and mode. This is what I have written so far :
    Start = new JButton("Start");
    Start.setBounds(150, 180, 90, 25);
    Start.addActionListener(new ActionListener() {     
    public void actionPerformed(ActionEvent ae) {
    Desktop.open(new File("C:\\eep.exe" + " " + filename + " " + mode + " " + key));
    However, I get the error "Cannot make a static reference to the non-static method open(File) from the type Desktop" on the Desktop.open command.
    What should I do? Is Desktop.Open the right way to go about this? If not, what is the right way to go about it?
    Thanks in advance.

    That has helped greatly, but I cannot pass command line arguments to it.
    Using :
    try {
        Desktop.getDesktop().open(new File("C:\\eep.exe"));
    catch (Exception e) {
       System.out.println("Error executing.");
    }I can execute eep.exe, but when I try to pass command line arguments to it, such as
    Desktop.getDesktop().open(new File("C:\\eep.exe" + " " + filename));it fails, get caught and prints "Error Executing."
    I have also tried loading the program, as well as some command line arguments into an array of strings :
    String[] cmdArray = {"C:\\eep.exe", filename};
    Desktop.getDesktop().open(new File(cmdArray));But it gives me the error "The constructor File(String[]) is undefined" on the
    new File (cmdArray)part of the command.

  • ERROR: -1639 INVALID COMMAND LINE ARGUMENT

    Trying to install software for Shuffle that Santa brought and get this error messsage...
    "Error: -1639 invalid command line argument. Consult the windows Installer SDK for detailed command line help."
    Install stops at this point.
    SOMEONE HELP... My kid is chomping at the bit !
    Thanks.

    Ok I'll do some more searching but I found something in the community forums.
    APPSearch can not return this data into a property, so instead, for some unspeakable reason, returns a value of Null, follwed by another Null. This means that the property is created, and populated with two null characters. Bad news if the property also happens to be a PUBLIC property. All public properties are passed as part of the command line sent in a stream to the background installer process by the Execute Action. Since this stream now contains a double null value in a property, the stream is prematurely terminated. This creates an invalid command line, and thus the 1639 error.
    This user solved it by using the MSi Cleanup installer util.
    EDIT: A little more info...
    This problem is almost impossible to detect through the MSI log files since our friends at Microsoft chose to limit the length of any line in the log. It is impossible to get a dump of the full command line that generates this error.
    EDIT2:Note that error 1639 only ocurrs when the install package is run from removable media. When the package is run from local storage, the behavior is far more obtuse. The background install process, failing to receive a complete command line, is forced to run as if there had been no UI session, which in turn causes the APPSearch action to run again as if the install was running in silent mode. This causes re-evaluation of all properties a second time, destroying the feature selections made in the UI session, and also forcing the install to run under user credentials instead of elevated, even though AdminUser, ALLUSERS and Privleged properties are set. This is a very serious error that causes total failure of the installation.

  • Reading character * at command line argument?

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class FindDemo {
    public static void main(String[] args) {
    Matcher m =
    Pattern.compile("[aeiouAEIOU]*(\*)[atcgAGCT]*").matcher(
    "agctaEvening is full of the linnet's wings");
    if (m.find())
    System.out.println(m.group());
    Help?
    (\*) - How can I read the * symbol from command line argument?

    If anyone can advise me, I would be very grateful.
    I have a program that takes arguments from command line:
    one a text file and the other a sequence to search against the file.
    The sequence can contain a * which represents more than one letter of the alphabet. e.g AM*N which should yield Amen, Amoran, american
    import java.io.*;
    public class FindTextInFileNine {
        public static void main(String[] args) {
            if(args.length != 2) {
                System.out.println("Usage: java FindTextInFile [file-name] [search-string]");
            else {
                String file = args[0];
                String search = args[1];
             String parameter = search.replaceAll(" ", "");
                String result = parameter(file, parameter);
                System.out.println(result);
        public static String parameter(String file, String parameter) {
            StringBuffer strb = new StringBuffer();
            parameter = parameter.toLowerCase();
    if (parameter.matches("[actgACTG]*") != false){
                      System.out.print("Correct parameters for sequence entered.");
    if (parameter.matches("[aeiouAEIOU]*") != true){
                      System.out.print("ERROR1: Incorrect parameters for sequence entered.");
            try {
                FileReader fr = new FileReader(file);
                BufferedReader input = new BufferedReader(fr);
                int lineNumber = 0;
                String line;
                     while((line = input.readLine()) != null) {
                         line = line.toLowerCase();
                         lineNumber++;
                      System.out.println(parameter.matches("[aeiouAEIOU]*"));
                         if(line.indexOf(parameter) != -1) {
                             strb.append("Found \""+parameter+"\" at line "+lineNumber+
                                         ", starting-index "+line.indexOf(parameter));
                             strb.append('\n');
                   else {
                   System.out.println("Sequence not found in file. Please check and try again");
                input.close();
            catch(IOException e) {
              System.out.println();
                 System.out.println("ERROR2: File not found. Please check file name, file extension and file location.");
            return strb.toString();
    }Any help appreciated.

  • Pass dynamic Command line arguments

    Hi,
    I tried to pass dynamic command line argument to Web start using the method :
    "javaws URL -D foo -D bar"
    as explained in the "Unofficial JWS/JNLP FAQ" that " You can pass your own system properties to your app using -D switch ....", but I got the following error at the start;
    error occurred while launching/running the application.
    Category: Invalid Argument error
    Too many arguments supplied: {http://...URL/my.jnlp, -Did=123 }
    p.s. I already added the"<property name='' value=''/> in the <resourse>, and modified the main class to get the parameter using System. getProperty();
    Did anyone try to this method before? What's wrong of this?
    Thanks in advance for your help.

    Thanks.
    here below is the jnlp file:
    <jnlp spec="1.0+" href="$$name" codebase="$$codebase">
    <information>
    <title>GUI Application</title>
    <vendor>PS</vendor>
    <description>PS GUI WebStart Version</description>
    <icon href="logo.jpg" />
    <offline-allowed />
    </information>
    <resources>
    <j2se version="1.3" />
    <jar href="lib/gui.jar" />
    <property name="id" value="zbc" />
    <jar href="lib/classes12.zip" />
    <jar href="lib/j2ee.jar" />
    <jar href="lib/jaas.jar" />
    <jar href="lib/jce1_2_1.jar" />
    <jar href="lib/jdom.jar" />
    <jar href="lib/xerces.jar" />
    <jar href="lib/local_policy.jar" />
    <jar href="lib/log4j.jar" />
    <jar href="lib/orion.jar" />
    <jar href="lib/sunjce_provider.jar" />
    <jar href="lib/US_export_policy.jar" />
    </resources>
    <security>
    <all-permissions />
    </security>
    <application-desc main-class="GUIFrame">
    </application-desc>
    and in the main class "GUIFrame", i use System.getProperty("id") t get the parameter, if I hardcode the value of the "id" in this jnlp file and use javaws URL, everything's fine, but not the "javaws URL -Did=value" which will return the error as mentioned.
    Thanks again for your help.

  • 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 read -Dname=value pair command line arguments

    Hi
    iam running one program called report.java as given below
    compile:
    javac report.java
    run:
    java report -Djava.path=home/arao/jaava1.5/bin
    my problem is how to read name and value pair given in command line argument.
    System.getProperty("java.path");//not working can anybody help how to read name and value
    pair of -D option

    If you put that string after the name of the class you are running, then it's a command line parameter. Your main() method can look at args[0] to see it. However it would be better if you just put it before the name of the class, where it's supposed to go if you want it to be treated as a system property.

  • Command line arguments

    Hey there,
    I have a program that uses a command line argument at runtime to get a txt file which is then loaded into my program.
    c:\>java FileName infile.txt
    I want to catch what args[0] is so I can print the file name the user entered to the screen when the program is running(so grab the infile.txt). Does anyone know what object I use to do this? Have I made sense?
    Thanks
    Dave

    Yeah I didn't realise I could use args[] like a string
    (first time using args you see....)
    but in my print statement I put ("Reading " ++
    args[0]) ionstead of
    ("Reading " + args[0])
    amazing the smallest thing the greatest stress :)You're not using "args" like a string
    this code:
    class EchoArgs{
    public static void main(String[] args)
    //args is a String array.
    for(int j=0; j<args.length;j++)
        System.out.println("args["+j+"] is:"+args[j]);
    }Would simply echo each arg on its own line back...
    But either way...all args passed from the Command line ARE strings.
    (arg[0] is the first string of the string array, etc..)
    Good ,luck,
    Dave

Maybe you are looking for

  • Copy/Paste difference in newer versions

    Hello, I developed some problems with my Acrobat Standard 7.0 install when trying to update to 7.1 (it wasn't recognizing my CS2 install disk as the correct source disk it was requesting) so in the mean time I downloaded the latest version so I could

  • CUIC 9.0 Custom Reporting

    Good Afternoon, I was wondering if anyone could help me with the following issue. I am looking to create customized dashboards for our contact center's supervisors. I'd like to add a customized report that includes All agent data for the current day

  • How to import, merge old and new personal dictionaries?

    I have DW CS4. Upgraded from DW8. How do I get all the "learned" words in the DW8 personal dictionary into the new DW CS4 dictionary? Thanks.  Ed

  • 0Contract as line item dimension

    Hi all, Should 0Contractnumber and 0Accountnumber be identified as a line item dimensions? but there are many relationships with these object? thks, rgds, wills

  • What movie file formats can be imported into iMovie?

    Can you directly import .avi, mpeg or .mov files? What about a Quicktime movie file? Just trying to figure out which file format iMovie will accept. I have a movie that was edited on Adobe Premiere and want to make sure I export the movie in the corr