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?

Dima Maligin
  • 1,386
  • 2
  • 15
  • 30
  • What parameters are passed to ProcessBuilder ? – Arnaud Dec 06 '15 at 07:59
  • @Berger please see edit... – Dima Maligin Dec 06 '15 at 08:04
  • 1
    Pass each parameter separately instead of a concatenated string. – assylias Dec 06 '15 at 08: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... – Dima Maligin Dec 06 '15 at 08:34
  • Not that I mind the downvote but at least take a moment to comment on it so my next question will improve... – Dima Maligin Dec 06 '15 at 08:37
  • @DimaMaligin I didn't downvote and I don't know why you got a downvote - your question is fine. As to why you need to send each arg separately vs as a concatenated string: http://stackoverflow.com/a/6856659/829571 – assylias Dec 06 '15 at 14:15
  • 1
    @assylias Thank you. I wasn't implying that you wore the one who downvoted, otherwise I would have tagged you... Thank you again... – Dima Maligin Dec 06 '15 at 14:18

0 Answers0