0

I am calling external myexefile.exe from java. The .exe File is executed properly in java but when I captured output of the .exe file through the following code, for each input every time it gives the same output 55.11 .However in command prompt output is different for each input . My sample code is as follows: a and b are input (double type) arguments of .exe file. I generated a and b value randomly before this code. Please not the the exe file gives right output when I run in command prompt.

Process p = Runtime.getRuntime().exec("C:\\filepath\\myexefile.exe a b");

BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
           String s;
           while ((s = stdInput.readLine()) != null) {
                System.out.println(new String(s));
           }

I just want to get the output of .exe file in Java. Or is there any way I can write that output as a text file?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1805525
  • 21
  • 1
  • 4
  • 1) Read the Java World article linked from the [`Runtime.exec` info. page](http://stackoverflow.com/tags/runtime.exec/info) & implement the recommendations. 2) Break the `String` args into `String[]` args. 3) Use a `ProcessBuilder` to create the `Process`. -- If you ask me about 2 or 3, it will indicate you have skipped 1. – Andrew Thompson Jan 22 '13 at 09:21
  • 1
    First, do everything Andrew said. Second, actually you are not giving myexefile the values of a and b, you're giving it the strings "a" and "b" as arguments. – dutt Jan 22 '13 at 09:23

0 Answers0