String cmdStr = "/bin/sh -c \"if [ -h /tmp/swwc12 ] ;
then echo exists; fi\"";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(getCmdArr(cmdStr));
public static final String[] getCmdArr(String cmdStr)
{
StringTokenizer st = new StringTokenizer(cmdStr);
String[] cmdArr = new String[st.countTokens()];
for (int i=0; st.hasMoreTokens(); i++) {
cmdArr[i] = st.nextToken();
}
return ( cmdArr );
}
期望的输出,以显示给定路径的符号链接是否存在。
实际结果: 命令是/ bin / sh -c“如果[[-h / tmp / swwc12];则回显存在; fi”
输出:
错误
[:-c:第0行:寻找匹配的“”“时出现意外的EOF [:-c:第1行:语法错误:文件意外结束