我正在尝试开发一个需要远程调试的安全系统。所以我正在寻找一种执行字符串中代码的方法,如下面的示例,但使用 java。
try {
String Code = "rundll32 powrprof.dll, SetSuspendState";// the code we need to excecute
Runtime.getRuntime().exec(Code);
} catch (IOException e) {
}
最佳答案
String Code = "rundll32 powrprof.dll, SetSuspendState";
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(Code);
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(output.toString());
请参阅以下网址了解更多信息http://www.mkyong.com/java/how-to-execute-shell-command-from-java/
关于java - 如何在 Java 中执行字符串中的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22710871/