0

I'm building a simple GUI for a python script with Java and I can't get it to run the script.

The method I am using to run cmd commands is this:

private void executeCommand(String command) {

    try {
        Process proc = Runtime.getRuntime().exec(command);
        BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        proc.waitFor();

        while (in.ready()) {
            System.out.println(in.readLine());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

I call the method like this:

executeCommand("cmd.exe /c subliminal download -l en -l ro " + selectedFile.getAbsolutePath());

The command runs perfectly if executed in command prompt but when called from Java nothing happens. Any ideas?

  • You should `split` the command string on spaces, [that's what](https://docs.oracle.com/javase/7/docs/api/java/lang/Process.html) you should be using. – Nir Alfasi Nov 21 '16 at 04:53
  • `String cmd = "cmd.exe /c subliminal download -l en -l ro " + selectedFile.getAbsolutePath(); Process proc = Runtime.getRuntime().exec(command.split(" "));` – Nir Alfasi Nov 21 '16 at 04:54
  • http://stackoverflow.com/questions/15464111/run-cmd-commands-through-java – newuserua_ext Nov 21 '16 at 04:55
  • Are you sure that you're in the same active directory, and that `cmd.exe` is in the `%PATH%`? – cwallenpoole Nov 21 '16 at 05:06

0 Answers0