Recieving input from command line
I want to recieve input from cmd/console.
I am running my game server, that server recieves input from the console. This works good if i run it from Eclipse. There I can just type into the console and my program recieves the input.
But when i export my program and run if through a batch file, I cannot enter anything into the command line.
I tried getting the input through these ways:
Code:
Scanner scanner = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Both these ways work when i run it in eclipse.
But as stated above, when I export my program as a .jar file, and I use a batch file to start my java program I cannot type anything into the opened command prompt.
My batch file looks like this:
Code:
java -jar spacegame_serverV0.1.6.jar
My program does run, because i can see the System.out.prinln that says that my server has started.
What do I need to do to make this run?
Recieving input from command line
I want to recieve input from cmd/console.
I am running my game server, that server recieves input from the console. This works good if i run it from Eclipse. There I can just type into the console and my program recieves the input.
But when i export my program and run if through a batch file, I cannot enter anything into the command line.
I tried getting the input through these ways:
Code:
Scanner scanner = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Both these ways work when i run it in eclipse.
But as stated above, when I export my program as a .jar file, and I use a batch file to start my java program I cannot type anything into the opened command prompt.
My batch file looks like this:
Code:
java -jar spacegame_serverV0.1.6.jar
My program does run, because i can see the System.out.prinln that says that my server has started.
What do I need to do to make this run?
Re: Recieving input from command line
Please go through the Forum Rules -- particularly the second paragraph. I've merged the thread you started in Advanced Java here.
Please don't double post again.
db
Re: Recieving input from command line
Depends on how you are tying to get input. If you're doing interactive input by asking the user to type something and the program reads it, then you need to enter that text into the terminal session where you are running the app - passing interactive input through a batch file would be difficult, and programs aren't written this way generally.
It may be possible in your batch file to redirect input, but I am not a windows person - I wouldn't know how to do that without some google foo. The problem is that when running your app from the batch file, any system.in statements in your app are coming from the context of the batch file, not the user's keyboard. You would need redirect the keyboard input from within the batch file to your app.
Re: Recieving input from command line
Quote:
Originally Posted by
DarrylBurke
Please go through the
Forum Rules -- particularly the second paragraph. I've merged the thread you started in Advanced Java here.
Please don't double post again.
db
I've locked another thread you started for the same question: http://www.java-forums.org/new-java/...tml#post314328
Any further violation of forum rules and you will be banned for a period. There will be no further warning.
db
Re: Recieving input from command line
Really helpfull there Darryl.
Instead of letting me spread my chances to find an answer you act like that.
Anyway i found the answer myself.
you just need to run the .bat file like this:
Code:
@ECHO OFF
java -cp <you-jar-file.jar> <your-main-class>
so for me it was
Code:
@ECHO OFF
java -cp spacegame_serverV0.1.6.jar server.KryoServer
Re: Recieving input from command line
Quote:
Originally Posted by
L19htn1n9
Really helpfull there Darryl.
Instead of letting me spread my chances to find an answer you act like that.
You are bound to abide by the rules that you agreed to at the time of signing up here, and the forum moderators are tasked to enforce those rules.
If you have an issue with those rules, you are free to start a thread in the Feedback/Suggestions section and hope that the forum administrator will respond.. You are not free to violate those rules.
db
Re: Recieving input from command line
That implies your jar file has not been created as an executable jar.
That would be the proper fix.