Results 1 to 3 of 3
- 07-03-2009, 05:15 PM #1Member
- Join Date
- Jul 2009
- Rep Power
Executing a sh file from java program in foreground
My purpose is to restart my Java application from within the application.
For this I have created a Java program that runs a sh file. This sh file has the command to start the same java Program.
when i run the parent Java program it executes the sh file and runs the Java Program in it in background. I want this program to run in foreground since the program takes inputs from the user. How can i make the program run in foreground.
Following is the code i use to execute the sh file
String LINUX_CLIENT_BATCH_FILE = "client.sh"; String command = "./" + LINUX_CLIENT_BATCH_FILE; Process theProcess=Runtime.getRuntime().exec(command); System.exit(0);
#!/bin/bash -e rm -rf sdt-socket-client.log* cp=".:conf:" for lib in `find -name \*.jar` do cp="$cp:$lib" done if [ $1 ]; then java -XX:NewSize=128M -XX:MaxNewSize=128M -XX:SurvivorRatio=8 -Xms350M -Xmx350M -Xrs -cp $cp com.sdt.A.D 'conf/' "localhost" 4445 'db/' $1 $2 $3 & echo $! > /usr/local/srb/srb_java.pid else java -XX:NewSize=128M -XX:MaxNewSize=128M -XX:SurvivorRatio=8 -Xms350M -Xmx350M -Xrs -cp $cp com.sdt.A.D 'conf/' "localhost" 4445 'db/' fi
- 07-03-2009, 07:00 PM #2
The main question: Why?Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 07-03-2009, 08:35 PM #3
I play around w/ a similar code on Windows. What happens is that Runtime.exec creates a new process, so you'll need to get the input/output streams and display it in the current shell. Otherwise it just runs in the background.
And also, "theProcess" needs to call waitFor() to wait for the shellscript to finish before exiting.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- By tilex in forum AWT / SwingReplies: 3Last Post: 04-02-2009, 08:16 PM
- By kanitha in forum New To JavaReplies: 0Last Post: 03-21-2009, 09:16 AM
- By mzatanoskas in forum New To JavaReplies: 2Last Post: 02-10-2009, 02:37 PM
- By arunsubramanian in forum Advanced JavaReplies: 5Last Post: 02-06-2009, 07:49 AM
- By TheBayWatchMan in forum New To JavaReplies: 4Last Post: 01-12-2008, 09:31 AM