Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Does LWJGL affect input from the command line? [unsolved]  (Read 833 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Posted 2013-11-27 22:47:13 »

I'm making a project that takes in data from the command line using the Scanner in the typical way. I am usually able to pipe from a text file or another device.

I switched out a lot of the code in the project to run with the LWJGL. In eclipse it works fine and the program reads things typed in the console. However, when I run it from the command line as a fat jar (using "java -jar project.jar") it does not receive and data piped into it or typed in the command line.

Does this have something to do with the structure of LWJGL displays or something similar? How can I successfully pipe data into my Jar?

Thanks
Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #1 - Posted 2013-11-27 23:14:22 »

When the program ends, all of the commands typed into the console while the program was running become visible, along with an error message. It looks like this:

>[command]
'[command]' is not recognized as an internal or external command, operable program, or batch file.
Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #2 - Posted 2013-11-28 01:52:14 »

For example, the program found here ( http://lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source ) works fine in eclipse, but the moment you take it to command prompt as a fatjar, it refuses to take any input from the user.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #3 - Posted 2013-11-28 02:19:41 »

Using JarSplice I have been able to make everything work as I would hope. As I need to put input into my program using the command prompt, I don't need to be able to click the icon to make it run, but rather use the command "java -jar program.jar"

So if I were to transfer my project to NetBeans (which could take a while) what would you suggest I look into so that the Jar will properly take in things from the console? I don't see much written about this subject currently and I'm not sure how to proceed.

Thanks
Offline opiop65

JGO Kernel


Medals: 123
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #4 - Posted 2013-11-28 02:41:02 »

Instead of porting everything over, make a simple batch file that runs the java program.

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #5 - Posted 2013-11-28 03:52:59 »

I am 99% sure this is a problem relating to input and not something else. My previous project that takes in console input in and identical way (through the Scanner) acts as expected. The program in question (along with that OpenAL demo I linked to) will not accept console input.

The thing is that when I type things into the console I AM using new lines. If I type in multiple commands (separated by new lines) then each "command" is parroted back out to me separately when the program ends.

So how can I configure everything so things are accepted into the scanner with each new line?

Thanks so much!
Offline opiop65

JGO Kernel


Medals: 123
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #6 - Posted 2013-11-28 04:00:24 »

Maybe split the spaces out of the command you just typed in using string.split? I think that's what you're asking for!

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #7 - Posted 2013-11-28 04:16:45 »

I don't quite see how that will help.
Here is my class that reads in the input, for reference. It runs in it's own Thread parallel to two other threads in my program:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
import java.util.Scanner;

public class Reader implements Runnable {

   Scanner sc = new Scanner(System.in);
   
   public Reader(){}
   
   public void run() {
      while(AudioRunner.keepGoing){
         String input = sc.nextLine();

         AudioRunner.pause();
         while(!AudioRunner.hasStopped){
            sleep(10);
         }

         Person.updatePeople(input);
         
         AudioRunner.resume();
      }
   }
   
   private void sleep(int time){
      try {
         Thread.sleep(time);
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }

}


The "updatePeople()" method does many operations on the received String. Here is what that method looks like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
public static void updatePeople(String input){
      Feed.nextLine(input);
     
      if(input.length() < 10 || !input.substring(0, 5).equals("user "))
         return;

      input = input.replace("user ", "");
      char numChar = input.charAt(0);
      int numPerson = Integer.parseInt(numChar+"");
     
      while(numPerson > numberOfPeople)
         new Person();

      people.get(numPerson-1).updatePerson(input);
   }

public void updatePerson(String input){
      if(input.charAt(0) != '('){
         updatePerson(input.substring(1));
         return;
      }
     
      input = input.substring(1,input.length()-1);
      input = input.replaceAll(" ", "");
     
      String[] coordsString = input.split(",");
      double[] coords = new double[3];
      for(int i = 0; i < 3; i++)
         coords[i] = Double.parseDouble(coordsString[i]);
     
      //left is more negative x
     setLocation(coords[0], coords[1], coords[2]);
   }


This code isn't meant to be understandable for anyone but me, really, because this is a pet project. The point is that I'm doing many operations on many received strings, and I am splitting them using ',' for the purposes of parsing strings into useful data. This works fine when I'm not using the LWJGL
Offline opiop65

JGO Kernel


Medals: 123
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #8 - Posted 2013-11-28 04:26:04 »

So hold on, you're trying to process multiple lines of input from the console using a scanner? I don't mean to be offensive, and I'm sorry if you already know this, but you know that once you hit enter after inputing commands in to the console, the data is stored in the string object and then is wiped so its ready to get the next set of data? So essentially unless you have the scanner on some sort of loop and you have a strong array, you can't process multiple lines in one go?

Sorry if I don't understand your question!

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #9 - Posted 2013-11-28 04:36:50 »

Ok, let me explain how this project is used.

That's exactly right, this project is accepting lines from the scanner on an infinite loop, updating things in the program according to structured strings put into the console.

The actual use of this is to read data from a microsoft kinect. Once again, this is only a pet project, so I didn't want to get bogged down in confusing libraries.

I found a program online that outputs data from the kinect into lines on the command prompt. So for example, if two people are walking around a room, the output can look like this, where a new line is written every fraction of a second or so:

1  
2  
3  
4  
5  
6  
7  
8  
user 1: head at (444, 444, 444)
user 2: head at (1001, 1000, 1000)
user 1: head at (444, 445, 444)
user 2: head at (1002, 1000, 1000)
user 1: head at (444, 446, 444)
user 2: head at (1003, 1000, 1000)
user 1: head at (444, 447, 444)
user 2: head at (1004, 1000, 1000)


By piping this data into my Jar in the command line, I can very easily pipe all this data into my program.
For example, I can do this like this in the command line:
1  
NISimpleSkeleton.exe | java -jar project.jar

where NISimpleSkeleton.exe is the program that outputs the data from the kinect into the command line. My JAR reads this data in real time and updates the program accordingly.

This method of organization works very well. The only problems came from when I changed the "engine" of this project to the LWJGL, at which point it stopped working for the simple reason that it stopped being able to accept the data from the command line.

That is how I am using the scanner, I hope that brings light to the issue.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jmguillemette
« Reply #10 - Posted 2013-11-28 08:08:04 »

Ignoring most of the tangents this discussion has already touched on..
can you post for me your "main" operation that launches your application.
What I'm suspecting is you actually have a thread issue. In which the buffer for the console where your typing is working just fine.. but nothing will be processed from it till your game ends.

thus why you see it when you quit.

-=Like a post.. give the author a medal!=-
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #11 - Posted 2013-11-28 08:42:30 »

The problem here has nothing to do with your code at all. It is JarSplice's fault. When running the JAR that is spit out by JarSplice, you are actually running its launcher, which, now that I look at the code, does not forward its stdin stream to your program. I'll talk to kappa about fixing this bug.

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #12 - Posted 2013-11-28 15:05:45 »

The problem here has nothing to do with your code at all. It is JarSplice's fault. When running the JAR that is spit out by JarSplice, you are actually running its launcher, which, now that I look at the code, does not forward its stdin stream to your program. I'll talk to kappa about fixing this bug.

Ah yes! Why didn't I think of that? Previously, before I moved my project to LWJGL, I had no reason to use Jarsplice, so I didn't. I didn't even imagine that Jarsplice would be the source of this problem. Thanks for pointing this out, I'll now work on finding a way to launch my project without Jarsplice...
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #13 - Posted 2013-11-30 00:15:24 »

I created my own FatJar a while back that uses the command line instead of a GUI and it properly forwards the IO. You can use that instead for now.

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #14 - Posted 2013-12-12 03:20:07 »

I get an error when I run it.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #15 - Posted 2013-12-12 03:37:52 »

What error?

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #16 - Posted 2013-12-12 04:03:46 »

The first time I ran it there was an error in the console (if I remember correctly) but I ran it again, and while there was no error, no window opened either.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #17 - Posted 2013-12-12 04:25:20 »

Well my tool runs only on the command line, as I mentioned here:
I created my own FatJar a while back that uses the command line instead of a GUI...

This way it's more useful for automation.

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #18 - Posted 2013-12-12 05:01:56 »

Ok cool, but how do I use it? What parameters does it take?
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #19 - Posted 2013-12-12 05:58:37 »

Have you tried running it without parameters first? Smiley

Offline nhmllr

Senior Member


Medals: 1
Projects: 3


slow and steady...


« Reply #20 - Posted 2013-12-12 11:31:35 »

Ok, It's asking me for parameters, but I don't understand where exactly to put them
Should I run it like this (if my jar is named Game.jar and I had eclipse export the libraries into the folder Game_lib

java -jar FatJar -lib Game_lib -main package.Main -output FatGame.jar

Where do I even specify to use Game.jar?
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #21 - Posted 2013-12-13 00:17:52 »

libs and natives cannot be folders, they must be a semicolon-separated list of files.

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (28 views)
2014-04-15 18:08:23

BurntPizza (25 views)
2014-04-15 03:46:01

UprightPath (40 views)
2014-04-14 17:39:50

UprightPath (22 views)
2014-04-14 17:35:47

Porlus (38 views)
2014-04-14 15:48:38

tom_mai78101 (62 views)
2014-04-10 04:04:31

BurntPizza (121 views)
2014-04-08 23:06:04

tom_mai78101 (221 views)
2014-04-05 13:34:39

trollwarrior1 (188 views)
2014-04-04 12:06:45

CJLetsGame (195 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!