aspose file tools*
The moose likes I/O and Streams and the fly likes Problem with HP UX ia64 while using Process proc = Runtime.getRuntime().exec( command ); Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem with HP UX ia64 while using Process proc = Runtime.getRuntime().exec( command );" Watch "Problem with HP UX ia64 while using Process proc = Runtime.getRuntime().exec( command );" New topic
Author

Problem with HP UX ia64 while using Process proc = Runtime.getRuntime().exec( command );

Manjesh Patil
Ranch Hand

Joined: Sep 24, 2010
Posts: 41

Hi
my test program does not seems to work on HP UX ia64 where as it works on Solaris and HP Ux PA
The JRE Version on HP UX ia64 is :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0.08-_04_may_2007_06_31)
Java HotSpot(TM) Server VM (build 1.5.0.08 jinteg:05.04.07-11:53 IA64, mixed mode)

Here is my test program

The results always the following output

Program started...date..
Program Failed to execute.

________________________________________________________
java.lang.NullPointerException
at java.lang.StringBuffer.<init>(StringBuffer.java:113)
at test.DateTest.main(DateTest.java:17)
________________________________________________________

as far as I know, " in.readLine()" is returning null.. I meant the "Runtime.getRuntime().exec( command );" not returning any result.
It happening with only HP UX ia64.It works fine on Solaris and all other platforms..
please someone can help me...?

Thanks
Manjesh
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

The output is probably sent to stderr, which you read using the getErrorStream() method. Or, and this is easier, dump Runtime.exec() and use ProcessBuilder instead. You can use it to redirect the process' error stream to its output stream, thereby allowing you to read it all from one stream.

And when working with Process, make sure to have read and understood this.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Manjesh Patil
Ranch Hand

Joined: Sep 24, 2010
Posts: 41

Hi Rob,
Thanks lot for your suggestions ,but unfortunately modified version of this program did not help me much

.
OUTPUT
----------------
<ERROR>
</ERROR>
DateTestModified: Process exitValue: 255

Its not printing the result of "date" command at all,
anyway the link you suggested me to look at is really nice..thanks for that
I suspect on JRE being used ..I am going to do more investigation on this.

Thanks again
Manjesh
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

The code you posted does not match the output. I tried it on my Ubuntu machine, and I got a NullPointerException. That makes sense, because the br.readLine() on line 20 is guaranteed to return null. After all, you've already read all data in the loop, and haven't reassigned br.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

I've modified your code slightly to use ProcessBuilder with error redirection, and I get the desired output. The code:
Manjesh Patil
Ranch Hand

Joined: Sep 24, 2010
Posts: 41

Hi Rob,
Thanks for your time.
I took your modified program ,compiled it on Solaris box and executed it .It worked with the following output,
<DATA>
Tue Aug 2 09:03:46 IST 2011
</DATA>
DateTestModified: Process exitValue: 0

Then I copied the .class file to customer's box running HP-UX ia64 and tried executing ..it did not throw any error but failed to give output
<DATA>
</DATA>
DateTestModified: Process exitValue: 255

But the strange thing is the same code works fine in our local HP-UX machine!!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

And when you run date from the console on the HP UX ia64 machine, do you get output? Perhaps it's not the Java code / JVM that's the problem but the date executable.
Manjesh Patil
Ranch Hand

Joined: Sep 24, 2010
Posts: 41

Hi Rob,
Yes the bare unix commands used to work as usual ,the problem is only when you run those commands via Java Process API.
However now the problem is solved. I replaced the jre with the new jre from the box where it was working fine. I am thinking something was currupted inside the JRE..
So the problem is now resolved.
Thanks for your suggestions ..
-Manjesh
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You're welcome, and I'm glad you resolved the problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with HP UX ia64 while using Process proc = Runtime.getRuntime().exec( command );