1

Java code to display current output of exe file and wait for input when needed for processing exe, after giving input display new output of the exe file and continue until process ends.

The following is the code that can take entire input needed for exe at a time and then displays entire output.

public class ExecuteSampleExe {
    public static void main(String args[]) throws IOException,InterruptedException {
        ProcessBuilder builder = new ProcessBuilder("SampleHelloWorld.exe");
        builder = builder.inheritIO();
        Process process = builder.start();      
        process.waitFor();
        System.out.println("Exit value" + process.exitValue());
    }
}
Snazzy Sanoj
  • 804
  • 1
  • 11
  • 28
Ajay Sreeram
  • 171
  • 2
  • 18
  • i want to execute c program from java, same like executing the same c program in console. (waiting for input and displaying output again waiting for input..) – Ajay Sreeram Jan 04 '16 at 14:59
  • So you have the C program, you want a Java program that can compile it and then run that program in the terminal? – Anindya Dutta Jan 04 '16 at 15:01
  • No need of compiling , i need only exe file obtained from c file to be executed. – Ajay Sreeram Jan 04 '16 at 15:02
  • Check the [Process](https://docs.oracle.com/javase/7/docs/api/java/lang/Process.html) class in Java. – Anindya Dutta Jan 04 '16 at 15:03
  • Yes i tried ,i am able to execute exe file only if i give entire input needed at a time.but i want to give input based on current execution status of exe file. – Ajay Sreeram Jan 04 '16 at 15:05
  • A place to start: http://stackoverflow.com/questions/10407308/redirect-stdin-and-stdout-in-java particularly the second answer – Mike Jan 04 '16 at 17:52
  • Documentation: http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html – Mike Jan 04 '16 at 18:00
  • I have used same library but i am unable to full fill my requirment – Ajay Sreeram Jan 05 '16 at 05:33

0 Answers0