Rumah > Soal Jawab > teks badan
public class Demo {
public static void main(String[] args) {
String path = File.separator + "home" + File.separator + "admin" + File.separator + "zlib_decompress"; // zlib_decompress 路径
String template = "chmod 777 %s";
String command = String.format(template, path);
String[] cmd = new String[] { "/bin/sh", "-c", "chmod 777 %s" };
try {
Runtime.getRuntime().exec(cmd); // chmod 777 /home/admin/zlib_decompress
} catch (Exception e) {
e.printStackTrace();
}
}
}
但直接执行chmod 777 /home/admin/zlib_decompress却可以,使用这种方式执行其他指令都可以但换成chmod就不行了是否涉及到其他权限问题呢?
PHP中文网2017-04-18 10:35:41
String[] cmd = new String[] { "/bin/sh", "-c", "chmod 777 %s" };
Arahan di atas%s
nampaknya bukanformat
Sekiranya ia diubah suai seperti berikut
String[] cmd = new String[] { "/bin/sh", "-c", command };