How can I call a C program in a Shell Script from Java

Reply

Join Date: Oct 2009
Posts: 1
Reputation: habibur is an unknown quantity at this point 
Solved Threads: 0
habibur habibur is offline Offline
Newbie Poster

How can I call a C program in a Shell Script from Java

 
0
  #1
Oct 22nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 48
Reputation: sneaker is an unknown quantity at this point 
Solved Threads: 7
sneaker sneaker is offline Offline
Light Poster
 
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster
 
0
  #3
Oct 22nd, 2009
Just run it as a an exe
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
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC