0

I need to run a native windows executable with some parameters:

ProcessBuilder pb = new ProcessBuilder(
        programFolder + SUB_PATH,
        params);

pb.redirectErrorStream(true);

try {
    System.out.println("running...");

    Process p = pb.start();

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
        String in = null;
        while (p.isAlive() && (in = reader.readLine()) != null) {
            System.out.println(in);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

} catch (IOException e) {
    e.printStackTrace();
}

This doesn't seem to work.

I checked that the generated command is correct and running fine when executed manually, but it seem like the above Process isn't executed at all and no error's or Exception's are throw'n.

What am I missing here?

EDIT: my problem isn't that the executable is not found but it's just not running.

EDIT: params value is:

String params = String.format("%d %s %s %s %d %d %d %d %d %d %d %d",
                            3,
                            videoPath,
                            bgImagePath,
                            distPath,
                            x1, y1, w1, h1,
                            x2, y2, w2, h2);

UPDATE: I replaced the ProcessBuilder with:

Process p = Runtime.getRuntime().exec(programFolder + SUB_PATH + " " + params, null, programDir);

and it now works fine...

I still want to know Why using the ProcessBuilder did not work?

7
  • What parameters are passed to ProcessBuilder ? Commented Dec 6, 2015 at 7:59
  • @Berger please see edit... Commented Dec 6, 2015 at 8:04
  • 1
    Pass each parameter separately instead of a concatenated string. Commented Dec 6, 2015 at 8:26
  • @assylias Indeed that solves the issue... Thank you! Can you expand on this issue? The generated command is exactly the same as the one with the parameters in one String yet now it works... Commented Dec 6, 2015 at 8:34
  • 1
    @assylias Thank you. I wasn't implying that you wore the one who downvoted, otherwise I would have tagged you... Thank you again... Commented Dec 6, 2015 at 14:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.