midnightray
March 15th, 2008, 03:19 PM
My first non uni and app. Basically installed php, mysql and apache from the repo's and wanted a gui to stop/start apache/mysql like XAMPP.
Ok after googling and playing around with netbeans. I have found this method of running commands through Java.
private String SHELL = "gnome-terminal";
private String SHELL_PARAM ="-e";
//Method to execute commands
public void doAction(String command,String servicename, String actionname){
ProcessBuilder launcher = new ProcessBuilder();
Map<String, String> environment = launcher.environment();
launcher.redirectErrorStream(true);
launcher.command(SHELL,SHELL_PARAM,command);
Process p;
String lines;
try {
p = launcher.start();
p.waitFor();
BufferedReader is = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader err = new BufferedReader(
new InputStreamReader(p.getErrorStream()));
String errMsg = "";
while ((lines = is.readLine()) != null) {
errMsg += lines + "\n";
}
while ((lines = err.readLine()) != null) {
errMsg += lines + "\n";
}
setStatusText(errMsg);
setStatusText(servicename + " " + actionname + "...");
} catch (Exception ex) {
ex.printStackTrace();
}
}
//method called from action listeners placed by netbeans like e.g.
// doAction("sudo /etc/init.d/apache2 stop", "apache", "stopped");
// last 2 params are for a message to be put in a text area,
// setting text area is a method, not included but a simple .setText()
The only really things I would like is, is there a way to get the full screen password box like when accessing admin stuff.
Can Java be themed to match Ubuntu's default human theme, it looks horrible really.
Ok after googling and playing around with netbeans. I have found this method of running commands through Java.
private String SHELL = "gnome-terminal";
private String SHELL_PARAM ="-e";
//Method to execute commands
public void doAction(String command,String servicename, String actionname){
ProcessBuilder launcher = new ProcessBuilder();
Map<String, String> environment = launcher.environment();
launcher.redirectErrorStream(true);
launcher.command(SHELL,SHELL_PARAM,command);
Process p;
String lines;
try {
p = launcher.start();
p.waitFor();
BufferedReader is = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader err = new BufferedReader(
new InputStreamReader(p.getErrorStream()));
String errMsg = "";
while ((lines = is.readLine()) != null) {
errMsg += lines + "\n";
}
while ((lines = err.readLine()) != null) {
errMsg += lines + "\n";
}
setStatusText(errMsg);
setStatusText(servicename + " " + actionname + "...");
} catch (Exception ex) {
ex.printStackTrace();
}
}
//method called from action listeners placed by netbeans like e.g.
// doAction("sudo /etc/init.d/apache2 stop", "apache", "stopped");
// last 2 params are for a message to be put in a text area,
// setting text area is a method, not included but a simple .setText()
The only really things I would like is, is there a way to get the full screen password box like when accessing admin stuff.
Can Java be themed to match Ubuntu's default human theme, it looks horrible really.