[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Interactive prompts from command line?

Posted on 2002-04-24
6
Medium Priority
?
387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Accepted Solution

by:
heyhey_ earned 210 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

656 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