• Post Reply Bookmark Topic Watch Topic
  • New Topic

input from process invoked via RMI

 
Adam Washington
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i'm writing a client-server application using RMI. the client presses a button which invokes a remote method which creates a process on the server side using Runtime.exec(). now i need to get the output from the process (standard output) and send it back to the client while it's being written. the idea is to keep the client updated on the process status.

any ideas...i don't think serializing an InputStream will work...right?

by the way, i'm relatively new at Java.

thank you!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, an InputStream isn't serialiazable, but the data inside it is. Assuming that the data being returned from your Process is character data, you can wrap the InputStream in an InputStreamReader, the a BufferedReader, and use readLine() to get the output from the process as a series of Strings. You could also just read byte[]s directly from the InputStream and return those, too, but I'm assuming it's going to be turned into Strings sooner or later.

Another idea to keep in mind is the length of time it takes for the process to execute... do you want to call one method and get the results as a return value after it's finished? Or do you want to make an interface for the client to send to the server, and have the server send pieces of data to the client when they are available?
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it sounds like you want a progress callback. I use one in a process that can span literally days. It's defined as an interface that gets implemented in one of the remote client classes.

There's some pretty decent docs on RMI callbacks, but I forget where. I just googled for them when I needed them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!