| | |
How can I call a C program in a Shell Script from Java
![]() |
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi all,
I have a C program namely NetLibExample.c.I have compiled it to get a NetLibexample executable in RHEL5. It is successfully running from the terminal itself by the syntax: ./NetLibExample
I have written a shell script to call the same.The shell script is test.sh
test.sh
cd /working/AVClient
mkdir habib_test
./NetLibExample
echo "1 image captured"
]This shell is running successfully and giving me the output( a new folder habib_test and output from the C program)
I have to call the shell script from Java program.The program is like this.
TestShell.java
public class TestShell {
public static void main(String[] args) {
try{
System.out.println("I am here to test the shell correctly");
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("/working/test.sh");
int exitVal = proc.waitFor();
}catch(Exception e){
e.printStackTrace();
System.out.println("Exception caught.........."+e.toString());
}
}
}
But when I am trying to call the shell from Java,shell is running properly as I am getting the new folder created from the shell.The java program is giving a exception:
java.lang.IllegalThreadStateException: process hasn't exited
at java.lang.UNIXProcess.exitValue(UNIXProcess.java:172)
at TestShell.main(TestShell.java:27)
Exception caught............java.lang.IllegalThreadStateException: process hasn't exited
Can anybody help me.Thanks in advance.
I have a C program namely NetLibExample.c.I have compiled it to get a NetLibexample executable in RHEL5. It is successfully running from the terminal itself by the syntax: ./NetLibExample
I have written a shell script to call the same.The shell script is test.sh
test.sh
cd /working/AVClient
mkdir habib_test
./NetLibExample
echo "1 image captured"
]This shell is running successfully and giving me the output( a new folder habib_test and output from the C program)
I have to call the shell script from Java program.The program is like this.
TestShell.java
public class TestShell {
public static void main(String[] args) {
try{
System.out.println("I am here to test the shell correctly");
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("/working/test.sh");
int exitVal = proc.waitFor();
}catch(Exception e){
e.printStackTrace();
System.out.println("Exception caught.........."+e.toString());
}
}
}
But when I am trying to call the shell from Java,shell is running properly as I am getting the new folder created from the shell.The java program is giving a exception:
java.lang.IllegalThreadStateException: process hasn't exited
at java.lang.UNIXProcess.exitValue(UNIXProcess.java:172)
at TestShell.main(TestShell.java:27)
Exception caught............java.lang.IllegalThreadStateException: process hasn't exited
Can anybody help me.Thanks in advance.
•
•
Join Date: Jul 2009
Posts: 48
Reputation:
Solved Threads: 7
0
#2 Oct 22nd, 2009
Hi
This is not my table
but I was just wondering if you already has been on this site:
http://www.javaworld.com/javaworld/j...229-traps.html
if not I believe there could be some useful information for you.
This thread:
http://forums.devx.com/showthread.php?t=147403
might possibly also be useful for you to reed.
This is not my table
but I was just wondering if you already has been on this site:http://www.javaworld.com/javaworld/j...229-traps.html
if not I believe there could be some useful information for you.
This thread:
http://forums.devx.com/showthread.php?t=147403
might possibly also be useful for you to reed.
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
0
#3 Oct 22nd, 2009
Just run it as a an exe
Boy what an old member i am
Richard West
Boy what an old member i am
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
![]() |
Similar Threads
- Interesting Issue with Shell Script!!!!!!!! (Shell Scripting)
- Call a shell script from a python script (Python)
- How To Call Shell Script In Java (Java)
- how to call various commands from a single script? (Shell Scripting)
- Executing Shell script in java program (Java)
- how to return value from shell script to the calllin C program (C)
- call the constructor of java class from script (Shell Scripting)
- Executing Shell script from Java code. (Java)
- Why my shell script doesn't delete a file ?? (Shell Scripting)
Other Threads in the Java Forum
- Previous Thread: An itext question...
- Next Thread: Create a sorted list
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





