繁体   English   中英

需要帮助从 Java JSP 运行递归触摸

[英]Need help running a recursive touch from Java JSP

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);
}


%>

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

String cmd = "find /home/ss/public_html/ss -exec touch {} \\;"

尝试分离命令 arguments:

// system command to run
String[] cmd = {"find","/home/abcdefg/","-exec","touch","{}",";"};

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

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

谢谢大家的快速回复!!

丹尼尔

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM