Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using RMI to call a C++ program

843829Jun 8 2001 — edited Jun 15 2001
Dear all,

I am using RMI program to remote call a C++ exe program. And I need to get back its printf value and return value. Is it possible to get this two values from C++ program to Java program?

Thx..

francis

Comments

A RMI client talks to a RMI server.

Did you write the C++ program to be a RMI server or client? Since writing a C++ program as a RMI server would be a fairly difficult undertaking and one would really understand RMI when done with it, I would guess that your exe is not a RMI server.

What you could do is write a RMI server in java. Then every time your client called a method on your RMI object it would cause the server to run the C++ exe by using Runtime.exec(). The server would collect the result and return it.
843829
Hi,

I have write a RMI server in java and use it to run my C++ exe. Same as you said. But it still can't return anything to me. I have checked the return stream from this process. Nothing inside.

Any idea??

Thx. a lot

Francis
You would have to provide more information before I could possibly have any ideas. Such as what 'nothing inside' means.

I suggest you seperate out the RMI code from the exec code. Get one piece to work and then the other and then combine them back together.

And use lots of System.out.println().
843829
Dear,

I have used the function available( ) to check the stream. But it return 0. So I said it is nothing inside.

And would you mind give me some examples about this. As I am a newbie in JAVA programming.

Thx.

Francis
You used available() to check which stream?

Presumably you mean the output from the Runtime.exec()? How many times did you check it? Did you wait for the process to terminate?

Reduce the code to the exec() code only and then post it.
843829
Dear,

Here is my code to run the Runtime.exec()

Process tmp = Runtime.getRuntime().exec( cmd )
OutputStream a = Runtime.getOutputStream
int ok = a.available();

And I want to ask how to wait process terminate?

Thx. a lot

Francis
Waiting...

int exitResult = tmp.waitFor();
if (exitResult != 0) {* probably not good*/}
843829
have you tried using exitValue() ? it returns 0 if the subprocess termintated normally
843829
have you tried using exitValue() ? it returns 0 if the
subprocess termintated normally
i should add that 0 is the usual return value. your app could return another value for normal termintation
843829
Dear,

It has returned 0. But I still can't get back the value from C program.

Thx. a lot

Francis
If waitFor returned zero then that is the exit value of the application that is being run. If you expect another value I would suggest looking at how the application is run (for instance if it is being run in a script/batch file that has nothing to do with java.) Or that you reexamine why you think it should be returning something besides zero.

1 - 11
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 13 2001
Added on Jun 8 2001
11 comments
159 views