0

Java中是否有任何方法可以使用 exec 方法执行递归触摸?

目标是设置一个简单的网页,当重新加载时会触及站点的目录,这样设计就可以保证不再发生缓存。请帮忙!!!

这是我到目前为止所拥有的,而不是在我的jsp中工作:

<%@ page import="java.io.BufferedReader,java.io.File,java.io.FileWriter, java.io.IOException, java.io.InputStreamReader, java.util.Map" %>

<%


String s = null;
// system command to run
String cmd = "find /home/abcdefg/ -exec touch {} \\;";
// set the working directory for the OS command processor
File workDir = new File("/home/ss/public_html/ss");

try {
Process p = Runtime.getRuntime().exec(cmd, null, workDir);
int i = p.waitFor();
if (i == 0){
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
// read the output from the command
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
}
else {
BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
while ((s = stdErr.readLine()) != null) {
System.out.println(s);
}

}
}
catch (Exception e) {
System.out.println(e);
}


%>
4

3 回答 3

1

您真的要触摸 下的文件/home/abcdefg吗?我可以想象你想触摸/home/ss/public_html/ss. 如果是这种情况,您必须更改 find 命令:

String cmd = "find /home/ss/public_html/ss -exec touch {} \\;"
于 2011-05-03T05:00:07.080 回答
1

尝试分离命令参数:

// system command to run
String[] cmd = {"find","/home/abcdefg/","-exec","touch","{}",";"};
于 2011-05-03T06:04:48.230 回答
0

一直沿着相同的路径 - 我想出了答案,它接近你们发布的内容:

<% String[] cmd = {"/bin/sh", "-c", "cd /xx/xx/xx/xx; find .-exec touch {} \;"}; 进程 p = Runtime.getRuntime().exec(cmd); %>

谢谢大家的快速回复!!

丹尼尔

于 2011-05-04T02:21:23.510 回答