Operating System - HP-UX
1847211 Members
2559 Online
110263 Solutions
New Discussion

Re: Java application. exitValue() of a HP-UX Script

 
Jes·s
Occasional Contributor

Java application. exitValue() of a HP-UX Script

I'am writing a Java aplication that will be executed under several plataforms and which make programs to execute.

I use a Process objet....

Process child=Runtime.getRuntime().exec(path);

...I do a waitFor() and then I get the exit value in an int variable whith exitValue() method.

This work well with executable files.

But I need to execute Unix scripts (HP-UX) and get the exit value.
At the last line of the scripts I write the instruction exit n (where n is an integer number), but the exitValue I get is always 255.

Could anyone help me?. How can I get the exit Value of a Unix Script?
JGNoguer
3 REPLIES 3
Mike Stroyan
Honored Contributor

Re: Java application. exitValue() of a HP-UX Script

I had to change "Process p" to "java.lang.Process p" to make your example run. You example produces correct results on the java 1.3 jvm. I can get it to produce correct results from the 1.2 and 1.1 jvms by adding a
#!/usr/bin/sh
line at the top of scriptFile. That changes the way that the exec runs the script, allowing a real exec(2) call to succeed. The kernel then runs the shell instead of the java process needing to exec a shell.
Jes·s
Occasional Contributor

Re: Java application. exitValue() of a HP-UX Script

Thank you very much, Mike Stroyan
I have successfully used the #!/usr/bin/sh solution.
JGNoguer
Jonathan Ortiga
New Member

Re: Java application. exitValue() of a HP-UX Script

this requires a shell script. how do i do it if i want to create the cmd on the fly and execute it without using a shell script?

thanks!