Running and communicating with exe files from Java.

I want to be able to start a windows exe from my Java and also communicate with. Say I send it some parameter and also when that exe is done to get its return value.

Runtime().getRuntime().exec

is that the way? How about the parameter passing between the exe and my Java game?

Bah!
Was kind of easy ;D

Process process=Runtime.getRuntime().exec(“blablabla.exe”);

  int i=process.waitFor();

Be sure to handle the I/O of the process, of it might hang suddenly (outputbuffer full)

It was easy starting an exe and getting return value. But now I want also to send parameters to it, alternatively start the exe with a parameter.

So, I tried.

Process process=Runtime.getRuntime().exec(Global.getInstallPath()+“myfile.exe”);
BufferedOutputStream bos = new BufferedOutputStream(process.getOutputStream());
bos.write(123456);

It seems the exe never receive those numbers and I do not know why…

flush

I tried 2 ways:

i)
bos.write(123456);
bos.flush();

ii)
bos.write(123456);
process.getOutputStream().flush();

neither worked

are you sure you are reading the data correct in the started exe?

No, I did not make the exe myself. So, my code looks ok then? I should be talking to the guy who made that exe then.

http://img512.imageshack.us/img512/7279/hannahmontanayoudthinkwj8.jpg

:wink: