Getting user name (at command line argument)

At the beginning of my program I need to prompt for the user name and then follow this with a welcoming message. Please help as I have not yet learnt this in my studies!

When prgramming java, and surely when learning it, alway use the documentation. You ken find it @ http://java.sun.com/j2se/1.3/docs.html To do input and output with the console you need the java.lang.System (Doc are @ http://java.sun.com/j2se/1.3/docs/api/java/lang/System.html ). The system object has an open inputstream called in wich reads the standard input, normally what users type on the console. So System.in.read() will get you a char that is typed on the console.
In your case it might be easier to create a BufferedReader.
BufferedReader input = new BufferedReader(System.in); will create a buffered reader that reads from the console. The advantage is that you can now use input.readLine() to read a complete line (until return key is pressed).
Succes
AVee

Similar Messages

  • Chnaging user name using command line

    We have 2 DB users (db1 and db2).
    in configuration tab, Services/JDBC/Connection Pools/bvdb on colsole, the user and password is listed.
    Usually we change DB user from one to other from console. I want to write script for it.
    I wanted to know the cammand with parameters to change the user and password.

    When prgramming java, and surely when learning it, alway use the documentation. You ken find it @ http://java.sun.com/j2se/1.3/docs.html To do input and output with the console you need the java.lang.System (Doc are @ http://java.sun.com/j2se/1.3/docs/api/java/lang/System.html ). The system object has an open inputstream called in wich reads the standard input, normally what users type on the console. So System.in.read() will get you a char that is typed on the console.
    In your case it might be easier to create a BufferedReader.
    BufferedReader input = new BufferedReader(System.in); will create a buffered reader that reads from the console. The advantage is that you can now use input.readLine() to read a complete line (until return key is pressed).
    Succes
    AVee

  • Filenames as Command Line Arguments: How?

    i need to create a program that involves taking in a file name as command line argument, reads the file and then displays its contents on the screen. it needs to work with any file with a .txt extension.
    The only thing i dont fully understand is how to read the file name as a command line argument e.g.
    "java FileReaderApp myfile.txt
    ----contents of file--------
    Thanks in advance
    Carl
    P.S. I have lready read the various helps, utils etc for java and still dont really understand

    Okay, first, it will help if you don't think of "filenames as command line args." The two concepts are totally independent.
    Command line args are Strings. What you do with those Strings is up to you. Processing the command line args is the same, regardless of whether they represent file names or the turnons of the last 50 playmates.
    The args array below contains the command line args.
    public static void main(String[] args) {
    // do stuff
    } Files are generally referred to using the java.io.File. It takes a String for the file name. It doesn't matter where the String comes from.
    Look at FileReader and BufferedReader to actually read the contents of the file.
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileReader.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedReader.html
    For the basic command line arg stuff, one of the following should have some info and examples
    http://java.sun.com/docs/books/tutorial/
    http://java.sun.com/learning/new2java/index.html
    http://javaalmanac.com
    http://www.jguru.com
    http://www.javaranch.com
    Bruce Eckel's Thinking in Java
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java

  • Command Line argument is not valid please verify the switch.......???

    hello frends
    We are currently getting this error.
    Command Line argument is not valid please verify the switch.
    The code used to send the mail is
    mail ="mailto:?subject="+escape(subject)+"&body="+escape(email);
    document.location = mail;
    return ;
    this is a javascript code to open outlook mail to send emails.
    the main problem is,when we write
    mailto:?subject=abc&body=uvwxyz......
    then we should be getting abc as subj and uvwxyz as the body..,and we r getting it....
    but when we include ""(double quotes ) in either the subject or the body..,it is showing the error line mentioned above.
    and if em using the html tags in the body part..,it's giving everything including the tags,which z not desired.
    kindly help me .....

    shikha6g wrote:
    i've thought..,you people are brainy enough to help me out in the javascript too...!!so..,i relied on this forum and have posted my problem,coz solving this thing was really imp for me.
    i din't knew,dat i'll get such circastic replys here.sorryTo me, being brainy implies that you are a smart thinker and good at problem solving. It doesn't mean that you know a language that you never learned.

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

  • How do I process user command line arguments inside of the Sequence Editor?

    Using TestStand 4.0, how would I go about storing "extra" command line arguments processed from the /runentrypoint command in the Sequence Editor specifically?

    djdewitt -
    TestStand 4.2 does not have this feature; however, we do have an internal issue (#163169) to track this request. You can actually get the commandline passed to the TestStand Sequence Editor using the below psuedo code in a sequence; however, currently the TestStand Sequence Editor displays a prompt when it does not recognize a custom token on the command-line and there is no way to suppress this.
    Locals.AppMgrRef = RunState.Engine.GetInternalOption(InternalOption_ApplicationManager);
    Locals.CommandsRef = Locals.AppMgrRef.CommandLineArguments;
    Locals.CountNum = Locals.CommandRef.Count;
    For i=0 to Locals.CountNum - 1
        Locals.CommandString = Locals.CommandRef.Item(i);
    End
    One suggestion is to use a batch file to write the commands to a dedicated text file and then launch the sequence editor. You can then use a sequence in the sequence editor to read from the file.
    Lastly, I just tried something and I do not necessarily recommend this, but I noticed that the Sequence Editor does not prompt when using the /goto token, so if I use the below command-line, it seems that no prompt appears, the goto command does nothing, and the psuedo code accesses the command-line tokens: 
    "C:\PathToApp\SeqEdit.exe" /goto "location tokens that do nothing" /run MainSequence "C:\PathToSequenceFile\GetCommandLineArgs.seq"
    Keep in mind that NI does not necessarily support this but it does seem to work for now.
    Scott Richardson
    National Instruments

  • Ant: how to get command-line argument?

    When using Ant to build Java source files, what is the syntax of obtaining command-line argument in build.xml?

    From the documentation:
    http://ant.apache.org/manual/running.html#libs
    Examples
    ant
    runs Ant using the build.xml file in the current directory, on the default target.
    ant -buildfile test.xml
    runs Ant using the test.xml file in the current directory, on the default target.
    ant -buildfile test.xml dist
    runs Ant using the test.xml file in the current directory, on the target called dist.
    ant -buildfile test.xml -Dbuild=build/classes dist
    runs Ant using the test.xml file in the current directory, on the target called dist, setting the build property to the value build/classes.
    ant -lib /home/ant/extras
    runs Ant picking up additional task and support jars from the /home/ant/extras location
    steps:
    - You define a property (like ${my.prop}) in your build.xml
    - You define it in the command line, like
    ant -Dmy.prop=chosen_value compile
    where "compile" is the target and "-Dmy.prop=chosen_value" defines the value of the property "my.prop" as "chosen_value".

  • 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

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

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

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

  • Changing the override file via command line arguments

    Is there a way to change name of the file Coherence uses to override coherence-config.xml via a command line argument? I'd like to specify different override filenames in different environments.

    I get the message that:
    2006-02-13 16:53:27.699 Tangosol Coherence 3.0.1/317 <D5> (thread=main, member=n/a): Optional configuration file "/home/noah/tools/tangosol-config/tangosol-coherence-override-dev.xml" is not specified
    I specified the following as the startup:
    java -Dtangosol.coherence.override=/home/noah/tools/tangosol-config/tangosol-coherence-override-dev.xml -Dtangosol.coherence.log.level=5 -classpath /home/ncohen/tools/tangosol-config:/home/noah/tools/tangosol/lib/coherence.jar com.tangosol.net.CacheFactory
    Where the tangosol-config directory contains my override file tangosol-coherence-override-dev.xml
    If I change the name of the override file solely in the cmd prompt, it doesn't find any of them. It just gives me the optional configuration file ..... is not specified. How does one go about fixing this? Thx.
    Message was edited by:
    noah

  • 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

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

  • Protecting command-line arguments from glob expansion

    Hi. I am writing a java program and I want to pass it a regular expression as a command-line argument. However, when I use certain regular expressions (e.g. [a-z]*), the java command-line interpreter recognizes this a glob expression and replaces it with names of files from the current directory.
    I am running the java interpreter from a Linux bash command line and I am enclosing the regular expression in single quotes (e.g. '[a-z]*') to protect it from the bash interpreter but the java interpreter is still getting to it. I have read other posts which stated that the java interpreter doesn't do this and that it must be the operating system's command-line interpreter that is doing it but I am sure this not the case.
    Can anyone help? Thank you. Eli

    I am running the java interpreter from a Linux bash
    command line and I am enclosing the regular
    expression in single quotes (e.g. '[a-z]*') to
    protect it from the bash interpreter but the java
    interpreter is still getting to it. I have read other
    posts which stated that the java interpreter doesn't
    do this and that it must be the operating system's
    command-line interpreter that is doing it but I am
    sure this not the case.It most certainly is the case that it's the shell, not Java. If the VM receives the String [a-z]* then that will be one the args.
    What may be happening is that java is actually a shell script, not an executable, and that shell script is expanding stuff.
    Do this: $ type java You'll get something like java is /usr/local/bin/java Then do $ file /usr/local/bin/java or whatever comes back. (Or just try to view the file with a text editor.)
    That file might be a shell script that sets some env vars and than calls the real java executable, passing it "$*" or "$@".
    If that's the case, you can try just invoking the executable directly, or modifying that shell script so that it won't do the expansion.
    If that's not the case, then post the exact command you're running and show your main method (includig code in the main that prints out each element of the args parameter).

Maybe you are looking for