1

First of all, I read all related topics and none of them answered my question.
I am developing a program in Java using Eclipse and I need to pass some arguments to the program continously after it starts.
For example somehow i need to give it this command by command line after it starts to execute:

CreateTable Students 2 10 10

And then I must be able to give more commands such as :

AddRecord Students Jack 1456

Run Configurations of Eclipse does not solve the problem since I can give arguments to the program only once by using Run Configurations. But I need to do it multiple lines?
Anyone has a solution? Thanks in advance

Oralet
  • 349
  • 1
  • 2
  • 11

2 Answers2

6

It doesn't seem to be possible in Eclipse according to this Question (which also lists possible workarounds). Update it's not possible to allocate System.console(), that much is true

But it does work with System.in (thanks Stephen C):

Scanner scanner = new Scanner(System.in);
String line;
while (true) {
    System.out.println("Type something please:");
    line = scanner.next();
    System.out.println(line);
}
Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • That's about what `System.console()` gives you when you are running within Eclipse. You should be able to type stuff at the Eclipse console for your application and read it using your application's `System.in`. – Stephen C Apr 29 '11 at 13:21
3

Sounds like you should read a sequence of commands from an inputstream, which might be connected to a Scanner (for live input) or a file (for runtime testing.)

Joseph Ottinger
  • 4,911
  • 1
  • 22
  • 23
  • Reading them from a file sounds fine but it creates some problems with my code. And I don't know what Scanner is but live input seems what i need :) – Oralet Apr 29 '11 at 13:00
  • 1
    What you need is not command line parameters, it's text input from the console. [Scanner](http://download.oracle.com/javase/6/docs/api/index.html?java/util/Scanner.html) is the standard Java class to input data from the console or another input stream. – Goblin Alchemist Apr 29 '11 at 13:10