Does LWJGL affect input from the command line? [unsolved]

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

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.

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.

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

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

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!

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

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:

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:

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

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!

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:

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:

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.

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.

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…

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.

I get an error when I run it.

What error?

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.

Well my tool runs only on the command line, as I mentioned here:

This way it’s more useful for automation.

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

Have you tried running it without parameters first? :slight_smile: