0

I have been fighting with Java trying to run an exe command in windows, I can launch notepad, but any time I try passing arguments I get nothing. I have searched over the last several days with tons of helpful ways to launch exe files, but I simply cannot figure out why none will run with arguments. Here is one of the examples I have tried today, using ProcessBuilder for starters.

public static void main(String[] args) throws Exception{
     ProcessBuilder p = new ProcessBuilder("C:/my/path/phantomjs.exe", "script.js", "site.com", ">", "output.txt");
     p.start();
}
Logical
  • 31
  • 4
  • See this [java-programming-call-an-exe-from-java-and-passing-parameters][1] [1]: http://stackoverflow.com/questions/5604698/java-programming-call-an-exe-from-java-and-passing-parameters – Shreyas Chavan Jul 18 '15 at 21:25
  • Thanks, but I have followed that one several times without any luck. My application will still not run. – Logical Jul 18 '15 at 21:30

1 Answers1

3

Redirection (the > character) is not actually part of the command. It's parsed by cmd.exe (or the Unix/Linux shell).

You want this:

ProcessBuilder p = new ProcessBuilder("C:/my/path/phantomjs.exe", "script.js", "site.com");
p.redirectOutput(new File("output.txt"));
p.start();

You probably should look at the summaries of all the ProcessBuilder methods available to you.

VGR
  • 40,506
  • 4
  • 48
  • 63