我有一个命令需要在 java 中按照以下方式运行:
C:\path\that has\spaces\plink -arg1 foo -arg2 bar "path/on/remote/machine/iperf -arg3 hello -arg4 world"
当路径没有空格时,这个命令可以正常工作,但是当我有空格时,我似乎无法让它工作。我尝试了以下方法,运行 Java 1.7
String[] a = "C:\path\that has\spaces\plink", "-arg1 foo", "-arg2 bar", "path/on/remote/machine/iperf -arg3 hello -arg4 world"
Runtime.getRuntime().exec(a);
也
String[] a = "C:\path\that has\spaces\plink", "-arg1 foo", "-arg2 bar", "path/on/remote/machine/iperf", "-arg3 hello", "-arg4 world"
Runtime.getRuntime().exec(a);
但似乎两者都没有做任何事情。关于我做错了什么的任何想法?