我需要你的帮助才能知道我的错误在哪里:)
public class Main extends JFrame{
public Main() {
EventQueue.invokeLater(new Runnable() {
public void run() {
setVisible(true);
}
});
}
public static void main(String[] args) throws IOException, URISyntaxException {
new Main();
File executor = File.createTempFile("Executor", ".sh");
PrintWriter writer = new PrintWriter(executor, "UTF-8");
writer.println("#!/bin/bash");
writer.println();
writer.println("java -$* > /tmp/output.txt 2>&1 &"); // ***
writer.close();
executor.setExecutable(true); // ***
File elevator = File.createTempFile("Elevator", ".sh");
writer = new PrintWriter(elevator, "UTF-8");
writer.println("#!/bin/bash");
writer.println();
writer.println(String.format("osascript -e \"do shell script \\\"%s $*\\\" with administrator privileges\"",
executor.getPath()));
writer.close();
elevator.setExecutable(true); // ***
Runtime.getRuntime().exec(String.format("%s -cp %s Main param", // ***
elevator.getPath(),
Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()));
}
}
此代码假设以管理员权限重新运行应用程序。询问管理员密码,但之后,应用程序无法运行。为什么 ?我的输出没有错误
谢谢