0

Hi i am trying to build a java program but i need run a C program with arguments and after i need get the return value..

Here is what i have done.

public static void main(String[] args) throws IOException {
    ProcessBuilder pr = new ProcessBuilder("C:\\Users\\MyFolder\\Desktop\\MyExe.exe", "param1", "param2");
    Process process = pr.start();
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
}

1 Answer 1

3

You can use:

int retVal = process.waitFor()

to block execution until the process is finished, and returns the return value.

See the docs for Process here: http://docs.oracle.com/javase/7/docs/api/java/lang/Process.html#waitFor()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.