1

I have this code:

try {
    Process p = new ProcessBuilder(
            "/Applications/TorBrowser_en-US.app/Contents/MacOS/./tor",
            "-f /Applications/TorBrowser_en-US.app/Library/filetctor/torrc")
            .start();
    p.waitFor();
    int exitVal = p.exitValue();
    System.out.println("Process exitValue: " + exitVal);
} catch (IOException e) {
    System.out.println(e);
} catch (InterruptedException e) {
    System.out.println(e);
}

Every time i execute it, i get a 255 exitValue. The process doesn't run properly.

If i run the program with only:

Process p = new ProcessBuilder("/Applications/TorBrowser_en-US.app/Contents/MacOS/./tor").start();

The process runs correctly. But i need to use the -f option.

What is the problem? Am i writing it incorrectly?

4

1 回答 1

3

每个参数应该是一个单独的字符串,而不是全部在一个空格分隔的字符串中。

请参阅文档中的示例

ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");

于 2013-05-27T14:48:52.560 回答