Command line input

...ok, maybe my subject wasn't too good, but say I have two files
blah.sh and another random program that runs blah.sh
blah.sh
#! /bin/bash
read $1
print $1
(or something like that)
and the other program to run 'blah.sh' and then input (while running) the program something for blah.sh to read?

skottish wrote:
zhurai wrote:...ok, maybe my subject wasn't too good
Yeah, not so good. Please use descriptive thread titles so that others may be able to benefit from this thread.
not sure exactly what to call it `-`
HashBox wrote:
Maybe you mean something like this?
main.sh
blah.sh Hello World
blah.sh
echo $*
tested it, but...not really =_=
zowki wrote:Instead of using examples like blah.sh and main.sh can you give us exactly what you want to accomplish? There may be a better way to do the job.
well...really I was thinking of if it was possible... but it's like:
main.sh:
#! /bin/bash
./two.sh
and
two.sh:
#!/bin/bash
read $1
print $1
how exactly would I get main.sh to input something like "Hello World" or whatever message into the read (as in, putting in *that* information w/o user input)
or however you say it ~_~

Similar Messages

  • Calling C from Java. C takes in a command line input

    Hello,
    I have created some basic JNI programs, in which the java file calls the C files. The way I could do it was directly calling the functions in the C files, which I needed. Now I am trying to call a C file from Java, and the C files takes in a command line argument after being compiled.
    Also after compiling the C file, it produces an exe. I cannot change the C file and also want to call it from Java using JNI (as I want to later put all this into a jar and jnlp file and put it on webstart).
    If anyone can help me on how to call the compiled C file and how to send in the input as a command line argument I would greatly appreciate it.
    Thanks
    Nick

    Now I know how to create a C wrapper file and a Java file in JNI format. Does this mean you want to run the exe files by calling the main() method through JNI. Yes you can do that BUT you will need to turn your exe file into a dll and then write a JNI wrapper to act as a bridge between the Java and the dll.Yes. Thats exactly what I want to do. I want to call the C files through JNI. But what I am asking is, how do I send in the input which is originally sent in as stdin? And also what are the steps to follow if I want to call a main method of the C files in the JNI.
    Up till now I have been using JNI to call functions from the initial C files from the C wrapper file. But now I want to call the .exe file by sending it a command line input. Or if you can suggest a better method that would be great.
    You can execute an exe file using ProcessBuilder then there is no need for a JNI wrapper. You must read the 4 sections of [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] and implement ALL the recommendations. Failure to do so will cause you much grief.
    You could achieve the same result but using a lot more code and a hell of a lot more effort by invoking the exe executables from JNI code that invokes the 'C' exec() library. Just thinking about that approach makes my eyes water!
    Well if I just use the exec() library I can do it, yes thats ture. But I wasnt sure if I did that, and then put this on Java Web Start, if non PC users can access it or not. If macs, and linux machines can access this even If i use exec, then my problem is solved.
    Thanks
    Nick

  • Unix command Line input and output

    Has anybody used Forte for now window application. Passing values through
    command line and get put as a return value. I am able to call Forte and
    pass input values but I do not know who to get the return value. Here is
    the shell script that I am running:
    #!/bin/csh
    # Ensure that the correct number of parameters were supplied #
    if (${#argv} < 2) then
    then
    echo "USAGE: ecapp Method Number Parm1 Parm2"
    exit 1
    endif
    ftexec -fi bt:$FORTE_ROOT/userapp/mwapp/cl0/mwapp_0 -fnw -fterm $1 $2
    The start class will return a string value after processing the request. I
    can use task.lgr.putline to output to the screen but that is not what I
    would like to do. I want to get the return value assigned to a variable in
    the shell script. One thing I do not know is that if Forte return a string
    that the script can use. Any help would be appreciated.
    thanks in advance
    ka
    Kamran Amin
    Forte Technical Leader, Core Systems
    (203)-459-7362 or 8-204-7362 - Trumbull
    [email protected]
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Hi,
    Did you try to set Task.Part.OperatingSystem.ExitStatus ? But, the ExitStatus is an integer.
    If you really need a string, I would use ExitStatus to know how it finished and an environment variable (Task.Part.OperatingSystem.SetEnv() to position it in your Tool code) to read the string back in the script.
    Hope this helps,
    Daniel Nguyen
    Freelance Forte Consultant
    Url : http://perso.club-internet.fr/dnguyen/

  • How to get COMMAND LINE input

    I am writng an application to add numbers inputted by the user at the command line in a DOS session in the java application. How do i read in input from the user?
    any help is much appreciated

    import java.io.*;
    public class ReadUser {
          static String userInput;
          static int sum = 0;
       public static void main(String[] args) {
          BufferedReader buff = new BufferedReader(new InputStreamReader (System.in));
          // get a string 4 times
          for (int i=0; i<4; i++) {
              System.out.println("Enter a Number");
              try
                   userInput = buff.readLine();
              catch(Exception ex)
                   System.err.println("Had a problem getting input");
                       // convert the string to an int and total it
              sum = sum + Integer.parseInt(userInput);
          // print the sum
         System.out.println("The total is " + sum);
             System.exit(0);

  • Command Line Input Terminating with Ctrl+D

    Hi,
    I am writing a program, that gets the input from the command line, what I want the program to do it continue to get the input until Ctrl+D is entered but I can not work out how to do this.
    Has anyone got any ideas.
    Thanks,
    Adam

    Are you working in a unix system? If so, Control-D means end-of-input, so you don't specifically look for a control-D character, you just check for end of input (end of the stream). This is provided in IO routines, in particular BufferedReader:
    "Returns:
    A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached"
    So for example:
    import java.io.*;
    public class test {
      public static void main(String argv[]) {
        String line;
        int i = 0;
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          while((line = in.readLine()) != null) {
            i++;
        } catch (IOException e) {
          e.printStackTrace();
        System.out.println("Now I'm done, having read " + i + " lines.");

  • Command line input concurrency?

    I'm building an agent program with a number of classes that each require the user to input information at the command line (not with args, but using Scanner(System.in)). I've only just now realised that running two of these agents simultaneously will result in them both using the same input. Is there any way to allocate separate channels, or to allocate a flow of control so that one will not receive input that is destined for the other?
    Thanks to anybody who can help.

    I'm a bit confused about the Synchronise keyword. I've figured out that i'll need a separate shell/window/console/terminal/whatever for each agent. I'm not sure I can use System.in and System.out in this case.
    Currently each agent class uses a class called InputOutput. The code for it is pretty simple:
    import java.util.Scanner;
    class InputOutput {
        private Scanner reader;
        public InputOutput() {
            reader = new Scanner(System.in);
        public String input() {
            return reader.nextLine().trim().toLowerCase();
        public void output(String text) {
            System.out.print(text);
        public String prompt(String prompt) {
            output(prompt + "  ");
            return input();
        public boolean yesOrNo(String question) {
            while(true) {
                try {
                    output(question + " (Y/N)  ");
                    char correct = input().charAt(0);
                    switch(correct) {
                        case 'y': return true;
                        case 'n': return false;
                        default: throw new Exception();
                catch(Exception e) {
                    output("Invalid selection\n");
        public String convertToDollars(int cents) {
            StringBuffer price = new StringBuffer(Integer.toString(cents));
            price.insert(0, '$');
            price.insert((price.length() - 2), '.');
            if(price.toString().contains("$.")) {
                price.insert(1, '0');
            return price.toString();
        public int convertToCents(String dollars) throws NullPointerException {
            StringBuffer price = new StringBuffer(dollars);
            int index = 0;
            while(index < price.length()) {
                if(Character.isDigit(price.charAt(index)) || price.charAt(index) == '.') {
                    index++;
                else {
                    price.deleteCharAt(index);
            String[] splitPrice = price.toString().split("\\.");
            switch(splitPrice.length) {
                case 1: return (Integer.parseInt(splitPrice[0]) * 100);
                case 2: int convertedPrice = (Integer.parseInt(splitPrice[0]) * 100);
                        if(splitPrice[1].length() <= 2) {
                            convertedPrice += (Integer.parseInt(splitPrice[1]) * (Math.pow(10, (2 - splitPrice[1].length()))));
                            return convertedPrice;
                default: throw new NullPointerException("Incorrect price format");
    }The main methods are input() (basically just a Scanner call; saves typing) and output() (basically a System.out.print call). I'm basically wondering if I can have each instance of this class open a new terminal window (or text window of some sort) where all its outputs will be displayed and all its inputs accepted, without conflicting with other instances of the object.
    Sorry if I'm not being clear. I'm still fairly new to java and the only interactive methods I know are Scanner and print/println :(

  • Testing Programs that use command line input

    Hi,
    I've written a program that takes values the user enters from the Standard Input (i.e. Dos/UNIX prompt) using the usual buffered reader. I now want to automate testing of this program using a second Java class.
    What is the best way to pass values from the test harness into the program, when it is expecting them from the Standard Input?
    hope someone can help!
    Cheers

    You can also create a new java process with the class you want to test.
    String commandToTest[] = {
    "java", "your.class", ...
    Process process = Runtime.getRuntime().exec( commandToTest );
    InputStream input = process.getInputStream();
    OutputStream output = process.getOutputStream();
    // and then send some input to your sub-process
    //          read the outputIn the same spirit, you can also work with two threads:
    - the first thread reassigns System.in, out and err
    spawns a new Thread that will call your.class.main(...)
    - the first thread sends some input to the new "System.in"
    reads the output from the new "System.out"

  • Problem with tokenized  input from command line

    I am trying to take an input from the command line, parse it to tokens and perform whatever operation is needed depending on the name of the token, on a binary tree of stacks for example, if i type 1 2 1 3 printLevelOrder, then the root of the tree should have 3, 2,1 in the stack, the left child should have 1 and the right child should be empty. and then a level order print of the tree should be performed.
    however what is happening when i run this code is the numbers are being put into the right stacks of the tree, but any commands such as printLevelOrder or PrintPopRoot are entering the code that is for placing numbers onto the stack instead of executing that command and skipping past this piece of code.
    so my question is, why is the if statement if (word =="printLevelOrder") not being executed when thats whats in the word ?
    example input and output shown below code fragment.
              try {
                  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                 String line = "";
                 while (line != "***") {
                      System.out.print("> prompt ");
                      line = in.readLine();
                      StringTokenizer tokenizer = new StringTokenizer(line," ");
                      String word = new String();
                      while (tokenizer.hasMoreTokens()) {
                             word = tokenizer.nextToken();
                             boolean notCommand = true;
                             if (word =="printLevelOrder") {
                                  theTree.printLevelOrder();
                                  System.out.println("(word ==printLevelOrder)");
                                  notCommand=false;
                             if (word == "printPopLevelOrder") {
                                  theTree.printPopLevelOrder();
                                  notCommand=false;
                             if (word == "printPopInorder") {
                                  theTree.printPopInorder();
                                  notCommand=false;
                             if (word == "printPopPreorder") {
                                  theTree.printPopPreorder();
                                  notCommand=false;
                             if (word == "printPopRoot") {
                                  theTree.printPopRoot();
                                  notCommand=false;
                             if (word == "***") {
                                  notCommand=false;
                             if (notCommand == true) {
                                  System.out.println("(notCommand == true)");
                                  boolean notPlaced = true;
                                  int v = 1;
                                  while ((notPlaced==true) && (v < theTree.size())) {
                                       if (theTree.element(v).isEmpty()) {
                                            theTree.element(v).push(Integer.valueOf(word));
                                            System.out.println("Inserting"+word);
                                            System.out.println("in empty stack at location: "+v);
                                            notPlaced=false;
                                       if (notPlaced==true) {
                                            if (  Integer.valueOf(word) >= Integer.valueOf( theTree.element(v).top().toString() )  ) {
                                                 theTree.element(v).push(Integer.valueOf(word));
                                                 System.out.println("Inserting"+word);
                                                 System.out.println("in stack at location: "+v);
                                                 notPlaced=false;
                                       v++;
              }valid inputs: int value, printLevelOrder, printPopLevelOrder, printPopInorder, p
    rintPopPreorder, printPopRoot, *** to quit
    prompt 1 3 2 4 2 printLevelOrder(notCommand == true)
    Inserting1
    in empty stack at location: 1
    (notCommand == true)
    Inserting3
    in stack at location: 1
    (notCommand == true)
    Inserting2
    in empty stack at location: 2
    (notCommand == true)
    Inserting4
    in stack at location: 1
    (notCommand == true)
    Inserting2
    in stack at location: 2
    (notCommand == true)
    Exception in thread "main" java.lang.NumberFormatException: For input string: "printLevelOrder"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:447)
    at java.lang.Integer.valueOf(Integer.java:553)
    at TreeStack.main(TreeStack.java:73)
    Press any key to continue . . .

    lol aww, shame that you forgot to do that. i had 10 / 10 for mine, and seing as the deadline is now well and trully over,
    here is the entire source for anybody who was following the discussion or whatever and wanted to experiment.
    additional files needed >
    http://users.cs.cf.ac.uk/Paul.Rosin/CM0212/Stack.java
    http://users.cs.cf.ac.uk/Paul.Rosin/CM0212/ArrayStack.java
    http://users.cs.cf.ac.uk/Paul.Rosin/CM0212/StackEmptyException.java
    http://users.cs.cf.ac.uk/Paul.Rosin/CM0212/StackFullException.java
    /*TreeStack.java - reads command line input of values and assigns them to stacks in a  binary tree and performs
    operations on the ADT. valid inputs: <int>,   printLevelOrder,   printPopLevelOrder,
    printPopInorder,   printPopPreOrder,   printPopRoot.         Terminates on invalid input.
    Written by George St. Clair.
    S/N:0208456         22/11/2005
    import java.util.Vector;
    import java.io.*;
    import java.util.StringTokenizer;
    public class TreeStack {
         private final int TREE_CAPACITY = 7 + 1;
         private final int STACK_CAPACITY = 10;
         Vector tree = new Vector(TREE_CAPACITY) ;
         //collect input from command line, add values to stacks at nodes of the teee
         //and perform required operations on the treestack
         public static void main (String [] args) {
              //create a tree of stacks
              TreeStack theTree = new TreeStack ();
              try {
                   //collect standard input
                  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                 String line = "";
                 while (line != null) {
                        System.out.print("");
                      line = in.readLine();
                      //tokenise input
                      StringTokenizer tokenizer = new StringTokenizer(line," ");
                      String word = new String();
                      while (tokenizer.hasMoreTokens()) {
                             //assign word to the token
                             word = tokenizer.nextToken();
                             boolean notCommand = true;
                             //perform operation on treestack depending on what word is
                             if (word.equals("printLevelOrder"))  {
                                  System.out.println("printLevelOrder");
                                  theTree.printLevelOrder();
                                  notCommand=false;
                             if (word.equals("printPopLevelOrder"))  {
                                  System.out.println("printPopLevelOrder");
                                  theTree.printPopLevelOrder();
                                  notCommand=false;
                             if (word.equals("printPopInorder"))  {
                                  System.out.println("printPopInorder");
                                  theTree.printPopInorder();
                                  notCommand=false;
                             if (word.equals("printPopPreorder"))  {
                                  System.out.println("printPopPreorder");
                                  theTree.printPopPreorder();
                                  notCommand=false;
                             if (word.equals("printPopRoot"))  {
                                  System.out.println("printPopRoot");
                                  theTree.printPopRoot();
                                  notCommand=false;
                             //if word was not a command it must be a number
                             if (notCommand == true) {
                                  boolean notPlaced = true;
                                  int v = 1;
                                  //starting at the root, find suitable place for number
                                  while ((notPlaced==true) && (v < theTree.size())) {
                                       //if the stack at v is empty, number goes here
                                       if (theTree.element(v).isEmpty()) {
                                            theTree.element(v).push(Integer.valueOf(word));
                                            System.out.println("inserting: "+word);
                                            System.out.println("in empty stack at location: "+(v-1));
                                            notPlaced=false;
                                       //if the stack is not empty
                                       if (notPlaced==true) {
                                            //if the value on the top of the stack is smaller than number, number goes onto the stack
                                            if (  Integer.valueOf(word) > Integer.valueOf( theTree.element(v).top().toString() )  ) {
                                                 theTree.element(v).push(Integer.valueOf(word));
                                                 System.out.println("inserting: "+word);
                                                 System.out.println("in stack at location: "+(v-1));
                                                 notPlaced=false;
                                       //if that node was no good, check the next one for suitability
                                       v++;
              catch (Exception e) {
                   //occurs when user inputs something that is neither a command, or a number, or upon EOF, or stack is full
         public TreeStack () {
              //create the TreeStack ADT by adding stacks in the vector, note vector 0 is instantiated but not used.
              for (int i = 1;i<=TREE_CAPACITY;i++)
                   tree.add(new ArrayStack(STACK_CAPACITY));
         public int size() {
              //return the size of the tree +1 (as 0 is not used)
              return tree.size();
         public ArrayStack element (int v) {
              //return the ArrayStack at v
              return (ArrayStack)tree.get(v);
         public int leftChild (int v ) {
              //return left child of v
              return v*2;
         public int rightChild (int v ) {
              //return the right child of v
              return v*2+1;
         public boolean children (int v ) {
              //search for children of v and return true if one exists
              for (int i =v;i<size();i++) {
                   if (i/2==v ) {
                         //left child found at i
                         return true;
                   if ((i-1)/2==v ) {
                        //right child found at i
                        return true;
              //no children found
              return false;
         public boolean isInternal (int v ) {
              //test whether node v is internal (has children)
              if (children (v)== true) {
                   //has children
                   return true;
              return false;
         //print the top value in each stack encountered on a level-order traversal of tree
         public void printLevelOrder() {
              //for every node of tree v
              for (int v = 1;v<size();v++) {
                   if (!element(v).isEmpty() ) {
                        //print the top value in stack v
                        System.out.println(" "+element(v).top());
                   else {
                        //stack at v is empty
                        System.out.println(" -");
         //pop off and print the top value in each stack encountered on a level-order traversal of tree
         public void printPopLevelOrder () {
              //pop off and print the top value in stack v
              for (int v = 1;v<size();v++) {
              //for each node of tree v
                   if (!element(v).isEmpty() ) {
                        //if v isnt empty print the top value in stack v
                        System.out.println(" "+element(v).top());
                        //pop the top value in the stack at v
                        element(v).pop();
                   else {
                        //stack at v is empty
                        System.out.println(" -");
         //pop off and print the top value in each stack encountered on an in-order traversal of tree
         public void printPopInorder () {
              printPopInorder (1);
         public void printPopInorder (int v) {
              boolean isInternal = false;
              if (isInternal (v)) {
                   //use a boolean for isInternal to save on running the method twice
                   isInternal = true;
                   //recursively search left subtree
                   printPopInorder (leftChild(v));
              //pop off and print the top value at v
              if (element(v).isEmpty() ) {
                   //stack at v is empty
                   System.out.println(" -");
              else {
                   //if v isnt empty print the top value in stack v then pop
                   System.out.println(" "+element(v).top());
                   element(v).pop();
              if (isInternal ) {
                   //recursively search right subtree
                   printPopInorder (rightChild(v));
         //pop off and print the top value in each stack encountered on an pre-order traversal of tree
         public void printPopPreorder() {
              printPopPreorder(1);
         public void printPopPreorder(int v) {
              //pop off and print the top value at v
              if (!element(v).isEmpty() ) {
                   //if v isnt empty print the top value in stack v then pop
                   System.out.println(" "+element(v).top());
                   element(v).pop();
              else {
                   //stack at v is empty
                   System.out.println(" -");
              if (isInternal (v)) {
                   //recursively search left and right subtrees
                   printPopPreorder (leftChild(v));
                   printPopPreorder (rightChild(v));
         //pop off and print all values from the stack at the root
         public void printPopRoot (){
              //while the root stack has values left
              while (!element(1).isEmpty()) {
                   //print, then pop
                   System.out.println(" "+element(1).top());
                   element(1).pop();
    }

  • Question about reading a string or integer at the command line.

    Now I know java doesn't have something like scanf/readln buillt into it, but I was wondering what's the easiest, and what's the most robust way to add this functionality? (This may require two separate answers, sorry).
    The reason I ask is because I've been learning java via self study for the SCJA, and last night was the first time I ever attempted to do this and it was just hellish. I was trying to make a simple guessing game at the command line, I didn't realize there wasn't a command read keyboard input.
    After fighting with the code for an hour trying to figure it out, I finally got it to read the line via a buffered reader and InputStreamReader(System.in), and ran a try block that threw an exception. Then I just used parseInt to get the integer value for the guess.
    Another question: To take command line input, do you have to throw an exception? And is there an easier way to make this work? It seems awfully complicated to take user input without a jframe and calling swing.
    Edited by: JGannon on Nov 1, 2007 2:09 PM

    1. Does scanner still work in JDK1.6?Try it and see. (Hint: the 1.6 documentation for the class says "Since: 1.5")
    If you get behaviour that doesn't fit with what you expect it to do, post your code and a description of our expectations.
    2. Are scanner and console essentially the same thing?No.
    Scanner is a class that provides methods to break up its input into pieces and return them as strings and primitive values. The input can be a variety of things: File InputStream, String etc (see the Scanner constructor documentation). The emphasis is on the scanning methods, not the input source.
    Console, on the other hand, is for working with ... the console. What the "console" is (and whether it is anything) depends on the JVM. It doesn't provide a lot of functionality (although the "masked" password input can't be obtained easily any other way). In terms of your task it will provide a reader associated with the console from which you can create a BufferedReader and proceed as you are at the moment. The emphasis with this class is the particular input source (and output destination), not the scanning.
    http://java.sun.com/javase/6/docs/api/java/util/Scanner.html
    http://java.sun.com/javase/6/docs/api/java/io/Console.html

  • Masking password on command line

    anyone know how to mask password from command line input
    before version 1.4 ?
    thx

    In his java section, there is a way here:
    http://www.rgagnon.com/bigindex.html

  • Problem in Executing Command Line

    Hello all,
       I am trying to execute the Perforce command lines through LabVIEW System Exec. These commands are working propery when directly entered in the command prompt, but through LabVIEW it is not working properly.
    "P4 client -i  <E:\template.txt"
    This command will read the file and create a client. Whenever we are doing this kind of  file operation (reading or writing), the command through LabVIEW is not working and the System Exec VI is giving the Standartd error output as  " Usage: client -i [ -f ] Unexpected arguments", but working perfectly in the comand prompt,

    hi cranen,
      use "cmd/c P4 client -i  <E:\template.txt" as command line input to the system exec.vi.
    Thanks and regards,
    srikrishnaNF

  • Constructors and command lines

    I would like to know how you allow command line input for a constructor created object.
    For example, my patient class has a constructor that will create a patient with 5 parameters id, name, age, etc.....
    public Patient(int d, String n, int a, int s, int x) {
                   id = d;
                   age = a;
                   tl = s;
                   name = n;
                   timearv = x;
    In my Clinic class I would like to allow a user to be able to enter details on the command line to create a patient......DON'T KNOW HOW!!!
    below is what i've come up with, but of course it doesnt work.....any help would be appreciated.....
    Clinic c = new Clinic();
                   System.out.println("Add patient details");
                   Patient x = new Patient(id, name, age, tl,timearv);

    Normally you present the user with a form consisting of fields the user fills in. When the user is finished and presses an OK button you read the filled-in fields and convert them to the internal types you expect/need. This information is then used to create objects.
    You can read about this in the Swing tutorial.
    A simpler way is to read from the standard input like this,
    http://javaalmanac.com/egs/java.io/ReadFromStdIn.html
    You can convert the read Strings to numbers like this,
    http://javaalmanac.com/egs/java.lang/ConvertNum.html

  • Reading commands from the command line

    Ok I've read quite a bit about streams, and I get the gist that you are suppose to open up a "stream," whether it from a file or from something else, and then you have to do all sorts of stuff to it like activate it or something, or whatever. But all I want to do is take an input from the command line, for example my name, and have it output "Hi [name]." I could swear I've done this before with a simple command like
    System.in.read() or something like that, but I read up on it and read is not a method that does that? So how does one just do a simple command line input into a variable...for what I want to do is control movement on a maze. If somebody can direct me to some documentation I would be happy as well. Thank you

    btw - "deadseasquirrels" - like the name. Have another program;-
    import java.io.*;
    import java.util.Random;
    public class Do_Writing {
       public static void main( String args[] ) throws IOException {
       BufferedReader in = new BufferedReader
                           (new InputStreamReader(System.in));
       Random rand = new Random();
       int i = 1+ rand.nextInt(10);
       String s1;
       System.out.println("Guess a number between 1 and 10");
          try {
             while ((s1 = in.readLine() ) != null) {
                // if( ... I'll leave the rest to you to figure out
                // when they get it right don't forget to include;-
                System.exit(0);
                in.close();
       catch (IOException ignore) { }                     
    }

  • Comparing input from command line to a String token problem

    Hi,
    I want to compare my input from the command line to a token.
    my command line looks like "java myProgram george bush president washington"
    The next command could be "java myProgram geoge president washington"
    Basically I have a text file which has a name, job and location field. The text file looks as follows
    jim, farmer, chicago
    paul, builder, texas,
    george bush, president, washington
    I am using string tokenizer with a "," as my field delimiter.
    My lecturer wants me to take the input from the command line so applets are out of the question. However even though there are 3 fields, args.length() could equal 4 because "george bush" is only the name but george is args[0] and bush is args[1]. Is there a way to have a delimiter on the command line instead of a space such a ",". Can anyone see any other way around this?
    Thanks

    1982. The year of.....wait for it.....
    Jack And Diane
    Tainted Love
    Key Largo
    Open Arms
    Do You Believe In Love
    Gloria
    Working For the Weekend and of course the GREATEST song of 1982...
    drum roll please......
    Heat Of The Moment.

  • Inputting non-visual characters from the shell (command line)

    is it possible to capture user input from the command line (using System.in or any other available method) that contains characters that are not printing characters and are not legal in a java.lang.String? i.e. is it possible to write a program that recognizes the arrows and CTRL, SHIFT, and ALT keys as input without using graphical (Swing or AWT) classes in the program?

    No. Shift, ALT and CTRL are key modifiers. Perhaps JCurses would allow you to check for these modifiers as Swing does.
    Brian

Maybe you are looking for