Total members 11806 |It is currently Mon Nov 18, 2019 3:41 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Calling shell script 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 test.sh

test.sh
Code:
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
Code:
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:
Code:
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


Please help me.Thanks in advance.




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : How can I call a C program in a Shell Script from Java
 program to run shell command line functions     -  
 Make a call using java     -  
 need help with java script in a pdf     -  
 Java script time parameter     -  
 How to create a file in java script using FireFox     -  
 Dynamic Frame-sets with java script protocols     -  
 Shell style comments     -  
 Simple code for taking input from shell     -  
 java program     -  
 java program     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com