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);
}
%>
答案 0 :(得分:1)
您真的想触摸/home/abcdefg
下的文件吗?我可以想象你想触摸/home/ss/public_html/ss
下的所有文件。如果是这种情况,则必须更改find命令:
String cmd = "find /home/ss/public_html/ss -exec touch {} \\;"
答案 1 :(得分:1)
尝试分离命令参数:
// system command to run
String[] cmd = {"find","/home/abcdefg/","-exec","touch","{}",";"};
答案 2 :(得分:0)
一直以来都是这样 - 我找到了答案,这与你们发布的内容很接近:
&LT;% String [] cmd = {“/ bin / sh”,“ - c”,“cd / xx / xx / xx / xx; find.-exec touch {} \;”}; 进程p = Runtime.getRuntime()。exec(cmd); %GT;
谢谢你们快速回复!!
丹尼尔