Results 1 to 8 of 8
  1. #1
    L19htn1n9 is offline Member
    Join Date
    Jul 2011
    Posts
    32
    Rep Power
    0

    Default 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:
    Java 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:
    Java 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?

  2. #2
    L19htn1n9 is offline Member
    Join Date
    Jul 2011
    Posts
    32
    Rep Power
    0

    Default 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:
    Java 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:
    Java 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?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Recieving input from command line

    Quote Originally Posted by DarrylBurke View Post
    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: console input, like crafkbukkit

    Any further violation of forum rules and you will be banned for a period. There will be no further warning.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    L19htn1n9 is offline Member
    Join Date
    Jul 2011
    Posts
    32
    Rep Power
    0

    Default 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:
    Java Code:
    @ECHO OFF
    java -cp <you-jar-file.jar> <your-main-class>
    so for me it was
    Java Code:
    @ECHO OFF
    java -cp spacegame_serverV0.1.6.jar server.KryoServer

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Recieving input from command line

    Quote Originally Posted by L19htn1n9 View Post
    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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Setting a value from an input in a Command line
    By beastman3226 in forum New To Java
    Replies: 3
    Last Post: 11-15-2012, 12:46 PM
  2. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  3. command line input to array
    By minusten in forum New To Java
    Replies: 13
    Last Post: 05-09-2011, 01:56 AM
  4. Replies: 3
    Last Post: 04-26-2010, 09:00 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •