Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-01-2011, 07:46 AM   #1
LQ Newbie
Registered: Oct 2008
Posts: 6

Rep: Reputation: 0
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);;

try {
Process start= p.start();

} catch (IOException e) {


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.

Old 11-01-2011, 01:11 PM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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
#start of script
> $tmp_file
java net.tinyos.sf.SerialForwarder -comm serial@/dev/ttyUSB0:telosb
echo 'DEBUG: java net.tinyos.sf.SerialForwarder returned' >> $tmp_file 
if cygpath -w / >/dev/null 2>/dev/null; then 
    echo 'DEBUG: test passed' >> $tmp_file 
    echo 'DEBUG: test failed' >> $tmp_file 
echo 'DEBUG: calling java Oscilloscope' >> $tmp_file 
java Oscilloscope
echo 'DEBUG: java Oscilloscope returned; script exiting' >> $tmp_file 
#end of script
1 members found this post helpful.
Old 11-01-2011, 02:01 PM   #3
LQ Newbie
Registered: Oct 2008
Posts: 6

Original Poster
Rep: Reputation: 0

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?

Old 11-01-2011, 09:18 PM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,375

Rep: Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755
which java >>$tmp_file
I suspect you have no (or minimal) env settings in the new cmd shell ...

Actually, try this at the top
set -xv
1 members found this post helpful.
Old 11-02-2011, 03:08 AM   #5
LQ Newbie
Registered: Oct 2008
Posts: 6

Original Poster
Rep: Reputation: 0

which java >>$tmp_file: gave the following output:

Does it say that the execution is taking place from that directory? But, what about It should set the directory to the new one specified in the java code. I couldn't find where the problem is.



java, shell script, ubuntu

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Running shell script in Ubuntu from a java program Ubuntu 4 10-28-2011 05:47 AM
How can I call a C program in a Shell Script from Java habibur Programming 3 10-24-2009 02:09 AM
booting to a fullscreen java program with a shell script sebastian.raghe Linux - Newbie 3 05-19-2005 02:42 AM
Creating a shell script to run Java program paultaylor Programming 7 11-12-2004 03:11 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration