0

Javaでexecメソッドを使用して再帰的なタッチを実行する方法はありますか?

目標は、リロード時にサイトのディレクトリにアクセスする単純な Web ページをセットアップして、設計がキャッシュが発生しないことを保証できるようにすることです。助けてください!!!

これは私がこれまでに持っていたもので、私の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 に答える