Only part of shell script executed from Java program.
I am facing some problem in running shell script from a java program. The script runs fine when executed from the terminal. But, when executed from the java program, not whole script is executed. My java code to implement shell script execution is:
File file = new File("/path/to/script"); String COMMAND= "./run"; ProcessBuilder p = new ProcessBuilder(COMMAND); p.directory(file); try { Process start= p.start(); } catch (IOException e) { e.printStackTrace(); } It seems only the first line is executed. "run" is the script name. I am using Ubuntu. The script is: #start of script java net.tinyos.sf.SerialForwarder -comm serial@/dev/ttyUSB0:telosb if cygpath -w / >/dev/null 2>/dev/null; then CLASSPATH="oscilloscope.jar;$CLASSPATH" else CLASSPATH="oscilloscope.jar:$CLASSPATH" fi java Oscilloscope #end of script Any suggestions why the whole script is not being executed? I observed that only the 1st command was executed. Thanks. |
Presumably you are seeing evidence that java net.tinyos.sf.SerialForwarder starts. Do have have any evidence that it finishes?
Presumably you are not seeing any evidence that java Oscilloscope starts. You could "instrument" the script to see what it does do Code:
#start of script |
Hi,
Thanks for the reply. Adding the debug lines on the script had the following output in the tmp/DebugFile: DEBUG: java net.tinyos.sf.SerialForwarder returned DEBUG: test failed DEBUG: calling java Oscilloscope DEBUG: java Oscilloscope returned; script exiting It shows that the end of the script is reached. But, why doesn't java Oscilloscope start? Is it because of the Classpath settings inside the script? Ashish. |
Try
Code:
which java >>$tmp_file Actually, try this at the top Code:
set -xv |
Hi,
which java >>$tmp_file: gave the following output: /usr/bin/java Does it say that the execution is taking place from that directory? But, what about p.directory(file)? It should set the directory to the new one specified in the java code. I couldn't find where the problem is. Thanks. |
All times are GMT -5. The time now is 01:43 PM. |