0
我试图从java运行一个命令。但命令没有执行。任何人都可以指出为什么?从java运行一个Linux命令
String path = dest+"/info_updated.csv";
File file = new File(path);
String command = "sed -i '/" + subscriberId + "/d' "+file;
System.out.println("command "+command);
Runtime run = Runtime.getRuntime();
Process p = null;
try {
p = run.exec(command);
InputStream errorStream = p.getErrorStream();
p.waitFor();
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("ERROR.RUNNING.CMD");
} catch (Exception e) {
e.printStackTrace();
} finally {
p.destroy();
}
return true;
}
在日志中它正在正确地打印命令。
command sed -i '/L13876110226750000/d' /usr/share/apache-tomcat-6.0.37/webapps/SMS/info_updated.csv
但它没有执行。
'-e'代替或补充'-i'? – user3159253
定义“不执行”,任何堆栈跟踪?另外,这很可能会使tomcat重新部署SMS webapp – 2014-03-28 06:29:03
没有shell =>不引用。 –