我试图通过Java应用程序运行MySQL服务器,但我无法通过我的应用程序执行终端命令。这是我正在使用的代码。
String[] commands = new String[]{"cd /usr/local/mysql/support-files/", "echo "+password+" | sudo -S ./mysql.server start"};
Process proc = new ProcessBuilder(commands).start();
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader err = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String msg = "";
while(true) {
msg = br.readLine();
if(msg == null) break;
System.out.println(msg);
}
但是这段代码没有执行那些命令。