Solved

Interactive prompts from command line?

Posted on 2002-04-24
6
376 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_
Comment Utility
you can use

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

Author Comment

by:luinzi
Comment Utility
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_
Comment Utility
for reading you can use

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String st = reader.readLine();
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 16

Accepted Solution

by:
heyhey_ earned 70 total points
Comment Utility
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
Comment Utility
Got it working! Thanks..................
0
 
LVL 16

Expert Comment

by:heyhey_
Comment Utility
so why did you give me grade B ?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now