1

My code so far:

public static void getTasklist(Table table, Login login){
    for(TableItem tableItem : table.getItems()){            
        try {
            if(tableItem.getChecked()){
                String command = ("cmd.exe /k tasklist /s " + tableItem.getText(3) + " /U .\\" + SettingsManager.getSetting(login, "Current-User") + " /p " + SettingsManager.getSetting(login, SettingsManager.getSetting(login, "Current-User")+"-PW"));
                Process p = Runtime.getRuntime().exec(command);

                BufferedReader in = new BufferedReader(
                        new InputStreamReader(p.getInputStream()));
                String line = null;
                while ((line = in.readLine()) != null) {

                    System.out.println(line);
                }                       
            }
        } 
        catch (IOException e) {
        }   
    }           
}

What I want to do: get task list information from a computer and print it to console (later print it to a window maybe). The host name from the computer comes from the checked table (tableItem.getText(3)) and the credentials comes from something I called settingsmanager (SettingsManager.getSetting....).

What works ATM: I get the Information and it got printed to console but after the last line the app hangs up.. I assume that the while loop never breaks but I am not sure about that..

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
hex2001
  • 11
  • 4
  • I suggest you read from the error stream as well as this could be either having it's buffer fill up or be reporting an error. – Peter Lawrey Nov 02 '18 at 11:57
  • Would be better if you could share the crash logs too. – Karthik Nov 02 '18 at 12:01
  • @Karthik it just hangs up.. no crash logs unfortunately... – hex2001 Nov 02 '18 at 12:13
  • @hex2001 may be a duplicate to this https://stackoverflow.com/a/13008847/3444930 – Karthik Nov 02 '18 at 12:23
  • 1) See also [When Runtime.exec() won't](http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html) for many good tips on creating and handling a process correctly. Then ignore it refers to `exec` and use a `ProcessBuilder` to create the process. Also break a `String arg` into `String[] args` to account for things like paths containing space characters. 2) `catch (IOException e) { }` Don't ignore exceptions! They inform us exactly what went wrong. Unless logging is implemented, at least call `Throwable.printStackTrace()` – Andrew Thompson Nov 03 '18 at 01:01
  • Hey Guys, thx for your help. @karthik your link help me a lot. You have been right was the same problem and i could fix it with the information. Also thx to Anrew for the link it also helped me a lot! – hex2001 Nov 06 '18 at 15:00

0 Answers0