Hi, Leute! Kann mir jemand vielleicht mit dem ProgressMOnitor helfen? Ich moechte einfach ein Perl Skript ausfuehren mit dem Knopfdruck und waehrend Ausfuehrung soll ProgressMonitor den Fortschritt anzeigen. HAbe schon Menge recherchiert, trotzdem bei der Ausfuehrung haengt mein Program!!! Und zwar richtig - muss dann manuell den PC neustarten!
Hier ist mein Code:
Danke sehr fuer Ihre Hilfe!!!
Hier ist mein Code:
Java:
class ExportButtonListener implements ActionListener {
private Process process;
int progress = 0;
public void actionPerformed(ActionEvent e) {
Thread thread = new Thread(new Runnable() {
public void run() {
final ProgressMonitor pm = new ProgressMonitor(null, "Lade...", "", 0, 100);
pm.setMillisToDecideToPopup(0);
pm.setMillisToPopup(0);
while (!pm.isCanceled() && progress <= pm.getMaximum()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
pm.setProgress(progress);
pm.setNote(progress + " ... " + " done");
}
});
try {
String masterip = _am.getAP().ip.getText();
String login = _am.getAP().login.getText();
char[] passwort = _am.getAP().password.getPassword();
String passwordnew = new String(passwort);
String path = _am.getMFP().output.getText();
String cmd_ipam = "cmd /c perl F:\\ubuntu\\export_subnets_ip_csv.pl" + " " + "-s" + " " + masterip + " "
+ "-u" + " " + login + " " + "-p" + " " + passwordnew + " " + "-o" + " " + path;
String cmd_backup = "cmd /c perl F:\\ubuntu\\export_database.pl" + " " + "-s" + " " + masterip + " "
+ "-u" + " " + login + " " + "-p" + " " + passwordnew + " " + "-o" + " " + path;
String cmd_module = "cmd /c perl F:\\ubuntu\\export_perlmodule.pl" + " " + "-s" + " " + masterip + " "
+ "-u" + " " + login + " " + "-p" + " " + passwordnew + " " + "-o" + " " + path;
String cmd_dns = "cmd /c perl F:\\ubuntu\\export_dns_zones.pl" + " " + "-s" + " " + masterip + " "
+ "-u" + " " + login + " " + "-p" + " " + passwordnew + " " + "-o" + " " + path;
if (_am.getMFP().ib_export.getSelectedIndex() == 0) {
process = Runtime.getRuntime().exec(cmd_ipam);
}
if (_am.getMFP().ib_export.getSelectedIndex() == 1) {
process = Runtime.getRuntime().exec(cmd_backup);
}
if (_am.getMFP().ib_export.getSelectedIndex() == 2) {
process = Runtime.getRuntime().exec(cmd_module);
}
if (_am.getMFP().ib_export.getSelectedIndex() == 3) {
process = Runtime.getRuntime().exec(cmd_dns);
}
while (process.exitValue() != 0 || process.exitValue() != 1) {
progress++;
System.out.println(progress);
}
System.out.println("done");
//process.waitFor();
if (process.exitValue() == 0) {
System.out.println("Command Successful");
System.out.println(path);
} else {
System.out.println("Command Failure");
}
BufferedReader in = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception ex) {
}
progress++;
}
}
});
thread.start();
}
}
Danke sehr fuer Ihre Hilfe!!!