Solved

Interactive prompts from command line?

Posted on 2002-04-24
6
378 Views
Last Modified: 2007-12-19
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...............
0
Comment
Question by:luinzi
  • 4
  • 2
6 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 6965355
you can use

System.out.print("Please enter Value 1:");
System.in.read(...);
0
 

Author Comment

by:luinzi
ID: 6965371
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?
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6965398
for reading you can use

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String st = reader.readLine();
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 16

Accepted Solution

by:
heyhey_ earned 70 total points
ID: 6965401
of course you must add some exception handling code

    try
    {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      String name = reader.readLine();
    }
    catch (IOException x)
    {
      x.printStackTrace();
    }
0
 

Author Comment

by:luinzi
ID: 6965413
Got it working! Thanks..................
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6965415
so why did you give me grade B ?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question