Link to home
Start Free TrialLog in
Avatar of luinzi
luinzi

asked on

Interactive prompts from command line?

Hi there,

I have written a program that runs on a Unix commandline. Sadly I have to parse it over 15 arguments when I run it. Is there anyway that I can in my main method get the program to run and then print line a prompt statement telling a user which parameter to enter so that I can then pump this into a variable for use? ie on the command line I want to see the following:

>java comparator --run the program
>Please enter Value 1: 3 --user enters this value
>Please enter output dir: c:\oput\ --user enters this
>Please.... etc etc

I assume I will need some kind of While statement?

Does anyone have a clue what i'm on about? Can anyone help?

Many Thanks...............
Avatar of heyhey_
heyhey_

you can use

System.out.print("Please enter Value 1:");
System.in.read(...);
Avatar of luinzi

ASKER

Thats great but I want to enter strings.

This is what I have done so far:

          InputStream f;

          String a;

          while ((a = f.read()) != null)
          {
               System.out.println("Enter Value: ");

          }
          System.out.println("Value entered was: "+ a);

It thinks I'm trying to enter an integer?

C:\jdk1.3\bin\comparator.java:155: incompatible types
found   : int
required: java.lang.String
          while ((a = f.read()) != null)
                                  ^
1 error

I don't even know if this is the right way of going about it? How would I use the System.in.read?
for reading you can use

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String st = reader.readLine();
ASKER CERTIFIED SOLUTION
Avatar of heyhey_
heyhey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of luinzi

ASKER

Got it working! Thanks..................
so why did you give me grade B ?