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

发布于 2024-11-04 20:41:10 字数 1068 浏览 2 评论 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);
}


%>

Is there any way in Java to use the exec method to perform a recursive touch?

The goal is to setup a simple webpage that when reloaded will touch the dir for the site so that design can guarentee caching is no longer happening. Any help please!!!

Here is what I have so far, and not working in my 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);
}


%>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小姐丶请自重 2024-11-11 20:41:10

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

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

Do you really want to touch the files under /home/abcdefg? I could imagine that you want to touch all files under /home/ss/public_html/ss. If that's the case you have to change the find command:

String cmd = "find /home/ss/public_html/ss -exec touch {} \\;"
轮廓§ 2024-11-11 20:41:10

尝试分隔命令参数:

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

Try to separate command arguments:

// system command to run
String[] cmd = {"find","/home/abcdefg/","-exec","touch","{}",";"};
抱猫软卧 2024-11-11 20:41:10

沿着同一条路 - 我找到了答案,它与你们发布的内容很接近:

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

谢谢你们的快速回复!

丹尼尔

All along the same path - I figured out the answer and it is close to what you guys posted:

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

Thank you guys for the quick response!!

Daniel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文