我正在使用.exe从一个ProcessBuilder
应用程序运行一个ProcessBuilder
。我可以运行.exe,并且可以传递标量参数,但是我想知道如何将数组作为参数传递?
我的代码看起来是:
Process process = new ProcessBuilder(path,
Integer.toString(firstParam),
"where i want array to be").
start();
发布于 2018-08-16 11:38:51
当使用ProcessBuilder
时,命令中的每个元素都是单独的参数。
String[] array = {"Item 1", "Item 2", "Item 3"};
String arg = String.join(",", array);
Process process = new ProcessBuilder("path/to/command.exe", "--argument-name", arg)
.inheritIO() // replace with your own IO handling if needed
.start();
我不认为您需要在引号中担心周围的arg
,因为ProcessBuilder
会把它作为单个参数发送给您。
上面的内容应该等同于这个命令行:
path/to/command.exe --argument-name "Item 1,Item 2,Item 3"
https://stackoverflow.com/questions/51875175
复制相似问题