944,181 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 512
  • Java RSS
Oct 22nd, 2009
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
habibur is offline Offline
1 posts
since Oct 2009
Oct 22nd, 2009
0
Re: How can I call a C program in a Shell Script from Java
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.
Sponsor
Reputation Points: 40
Solved Threads: 13
Junior Poster in Training
sneaker is offline Offline
76 posts
since Jul 2009
Oct 22nd, 2009
0
Re: How can I call a C program in a Shell Script from Java
Just run it as a an exe
Boy what an old member i am

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: An itext question...
Next Thread in Java Forum Timeline: Sorting arrays while retaining original index





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC