I have the following code:
ProcessBuilder pb = new ProcessBuilder( "java", "-jar", "test.jar", Integer.toString( jobId ), Integer.toString( software ), Integer.toString( entryPoint ), application );
pb.directory( new File("/home/userName/TestBSC") );
Process proc = pb.start();
When running the jar file from my terminal with this command:
java -jar test.jar 135 3 3 appName
Then it works like a charm. The jar pushes some stuff in my database so I see that it is working. But when doing it from my JavaServlet with the processBuilder-code mentioned above, I don't get any data in my database and I don't get any errors either.
However the process itself is running, I checked it with "ps ax" in my terminal. So I wonder where is here the difference? What am I doing wrong?
Has someone an idea?
Edit: more Code:
ProcessBuilder pb = new ProcessBuilder( "java", "-jar", "test.jar", Integer.toString( jobId ), Integer.toString( software ), Integer.toString( entryPoint ), application );
pb.directory( new File("/home/userName/TestBSC") );
Process proc = pb.start();
System.out.println( "Job running" );
proc.waitFor(); // wait until jar is finished
System.out.println( "Job finished" );
InputStream in = proc.getInputStream();
InputStream err = proc.getErrorStream();
byte result[] = new byte[ in.available() ];
in.read( result, 0, result.length );
System.out.println( new String( result ) );
byte error[] = new byte[ err.available() ];
err.read( error, 0, error.length );
System.out.println( new String( error ) );
UPDATE:
I tried to call a shell-script instead of my jar. So I called a shell script with the processbuilder from my java-file.
My shell script does this:
java -jar test.jar "$1" "$2" "$3" "$4"
Well it still didn't work. So I tried this:
gnome-terminal -x java -jar test.jar "$1" "$2" "$3" "$4"
And suddenly it works!! BUT it opens the gnome-terminal, which executes the jar-file.
So I wonder, could this has anything to do with the output which isn't shown in eclipse? I really don't get it. This is now a nice workaround. But I really would like to get this working without having my terminal opening each time the jar gets executed.