missing command output

For some Reason the output that i get from executing a command via Runtime.getRuntime().exec("command") is incomplete.

In this case I only get "Reading packet List... " isntead of also getting things likke "All packets are up to date." etc even though i get those when executing it manually in sheel. It ried stuff with debugger but wasnt able to find a work around for the problemm.

Environment Linux Debian Server
 // Run apt update command
            Process updateProcess = Runtime.getRuntime().exec("apt update");
            updateProcess.waitFor();
            // Read the output of apt update
            BufferedReader updateReader = new BufferedReader(new InputStreamReader(updateProcess.getInputStream()));
            String updateLine;
            boolean upToDate = false;

            // Read all the lines of output
            StringBuilder updateOutput = new StringBuilder();
            while ((updateLine = updateReader.readLine()) != null) {
                updateOutput.append(updateLine).append("\n");
                System.out.println("Proccess Reader: " + updateLine);
            }

            // Check if all packages are up to date
            if (updateOutput.toString().contains("All packages are up to date.")) {
                upToDate = true;
            }
I am am aware that running java as root would be a great security risk. I circumvented it by using a dummy user which does not have sudo permission and allowing him to execute apt update and apt list --upgradeable.
Was this page helpful?