How can I call a C program in a Shell scipt from java


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 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. 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/"); 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 runnin g 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( at TestShell.main( Exception process hasn't exited Please help me.Thanks in advance.

View Comments
Join the discussion
Be the first to comment on this article. Our Commenting Policies