Hi Ashish, When executing a process from Java, the process is executed as a binary, or at least without any environmental variables set. You could run the shell program (e.g., /bin/bash) with the script to execute as an argument. In addition, you might want to use absolute paths for the binaries executed in the script.
To debug such a problem, it is often helpful to capture stdout and stderr of the process you are trying to execute and to see whether the process returns an error value when terminating (I am not talking about the exception, but about the return value of the process). Cheers, Urs On 11/2/11 12:08 AM, Ashish Sharma wrote: > Hi, > > I have been developing a Java program and some functionality of the > program is to run tinyos specific commands from within the program. > Since, we have few lines of codes, I am using shell script and running > the script from my java program. I am having some problems in > executing the command 'java Oscilloscope' from my program. > > The java code to execute shell script is: > > # Java code > File file = new > File("/opt/tinyos-2.x/apps/Oscilloscope/java"); > String COMMAND= "./run"; > ProcessBuilder p = new ProcessBuilder(COMMAND); > p.directory(file); > try { > Process startProcess= p.start(); > > } catch (IOException e) { > e.printStackTrace(); > } > # End of java code. > > The script has following commands: > > # start of script > java net.tinyos.sf.SerialForwarder -comm serial@/dev/ttyUSB0:telosb& > sleep 4 > if cygpath -w />/dev/null 2>/dev/null; then > CLASSPATH="oscilloscope.jar;$CLASSPATH" > else > CLASSPATH="oscilloscope.jar:$CLASSPATH" > fi > java Oscilloscope > # end of script > > I cannot see the Oscilloscope program running. The script works fine > when executed from the terminal but from my java program is only > executing the SerialForwarder. > > Is it because of the classpath command in the script? I also tried to > execute the script by passing environment variable classpath (as in > the script), but that too didn't work. What can be the possible cause > and solution? > _______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help