Skip to Main Content

Java SE (Java Platform, Standard Edition)

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!

Desktop class problem

843807Aug 11 2010 — edited Aug 12 2010
The code below does nothing. No file opened, no exception thrown, no output.
What can I do to discover the problem?
It does indeed execute the desktop.open(file) line.
Using JDK 1.16.0_81
File file = new File(pathAndFileString); // an existing text file
if (Desktop.isDesktopSupported()) {
	Desktop desktop = Desktop.getDesktop();
	if (desktop.isSupported(Desktop.Action.OPEN )) {
		try {
			desktop.open(file);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
	else {
		System.out.println("Desktop.Action.OPEN not supported");
	}
}
else {
	System.out.println("Desktop not supported");
}

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 Sep 9 2010
Added on Aug 11 2010
8 comments
3,620 views