Redirection with Runtime.getRuntime().exec() doesn't work

后端 未结 2 1724
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 21:58

I need to execute a command from a program. The command line is ok, I tried it in the terminal, but it doesn\'t work in the program.

I add a copy from my code:

2条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 22:41

    If you have Java 7, it's easier:

    Process p = new ProcessBuilder()
        .command("exiftool", "-a", "-u", "-g1", "-j",
                 new File("videos", filename).toString())
        .redirectOutput(new File("metadata", filename + ".json"))
        .start();
    

    This falls under "solution 2", but the runtime library takes care of the boilerplate.

提交回复
热议问题