| | |
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 34 Days Ago
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 34 Days Ago
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 |
2dgraphics account android api apple applet application array arrays automation banking bidirectional binary binarytree birt bluetooth chatprogramusingobjects class client code columns component database derby design eclipse encryption error errors expand fractal game givemetehcodez graphics gui guidancer homework html ide if_statement image inheritance integer intellij interface j2me java javadesktopapplications javaprojects jlabel jme jni jpanel jtextfield julia linux list map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source problem program programming project property recursion reference ria scanner search server set sms smsspam sort sourcelabs splash sql sqlite static stop string support swing testautomation threads tree ui unicode validation windows





