communications between two processes in java

Hi,

I am using Runtime.exec() to execute a java program in a seperate jvm. I want to send a message from the java program which is executed in the seperate jvm to the main program which invokes Runtime.exec().

Could anyone can help me in this regard?

Thanks,

Shashidhar Kotta

[306 byte] By [shashidhar_kottaa] at [2007-11-26 16:41:28]
# 1
You can use sockets.
kajbja at 2007-7-8 23:08:29 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi,

Runtime.exec() returns a Process object. You have access to three different Streams in this process.

Process p = Runtime.exec("mysubprocess" ) ;

p.getInputStream() returns an InputStream that contains everything that you write into the normal OutputStream of mysubprocess (using System.out.print... functions)

p.getErrorStream() returns an InputStream that contains everything that you write into the error stream within mysubprocess (using System.err.print... functions) .

p.getOutputStream() returns an Outputstream that maps to the standard input stream of mysubprocess.

E.g.

You have a Class called IamCalledViaExec with a main method.

You have a class called IamTheCaller.

Within IamTheCaller you should be able to do something like that :

Process p = Runtime.exec("java IamCalledViaExcec" ) ;

InputStream is = p.getInputStream() ;

If you do a

System.out.println("This is a message from me") ;

within IamCalledViaExec , you should be able to read it from the InputStream is in IamTheCaller.

g_magossa at 2007-7-8 23:08:29 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi,Thanks for the solutions.But my problem is instead of reading the input or output streams i want to read the child process's instance variables.Is there any way to do that?
shashidhar_kottaa at 2007-7-8 23:08:29 > top of Java-index,Java Essentials,Java Programming...
# 4
No.
DrClapa at 2007-7-8 23:08:29 > top of Java-index,Java Essentials,Java Programming...