io - Sharing i/o between java programs -



io - Sharing i/o between java programs -

this question regards redirection of input , output between 2 java programs. source code simplified illustration of problem below.

this prog1:

import java.io.*; public class prog1{ public static void main(string[] args) throws ioexception{ runtime rt = runtime.getruntime(); process prog2 = rt.exec("java prog2"); system.out.println("prog2 has executed."); } }

on separate file, i've written prog2, execute net explorer verify execution successful:

import java.io.*; public class prog2{ public static void main(string[] args) throws ioexception{ bufferedreader in = new bufferedreader(new inputstreamreader(system.in)); system.out.print("enter string: "); system.out.println("you entered " + in.readline() + ". starting explorer..."); runtime.getruntime().exec("c:\\program files (x86)\\internet explorer\\iexplore.exe"); } }

this see if run prog2:

> java prog2 come in string: hello ** here programme waited input ** entered hello. starting explorer... ** here net explorer opens new window **

this see if run prog1:

> java prog1 prog2 has executed. ** net explorer opens new window **

note prog2 did not prompt me input, , did not output anything. goal next occur:

> java prog1 come in string: hello ** here wish programme await input ** entered hello. starting explorer... ** here wish explorer window open ** prog2 has executed.

i beleive problem require knowledge of i/o redirection, unfortunately quite unexperienced in area. give thanks in advance.

devin

replace this:

process prog2 = rt.exec("java prog2");

with this:

process prog2 = new processbuilder("java", "prog2").inheritio().start();

processbuilder preferred replacement runtime.exec methods.

java io inputstream outputstream

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -