Created this function to input unix commands and output the outputs of that unix command. But, I am having trouble with the unix commands I use. "ls" works to output the list of files, but if I do "ls -lart" it will output null. Having trouble further debugging or why this doesn't work. Code below.
private String[] unixCommand (String command, Boolean boolOutput) throws IOException, InterruptedException{
Process run;
int i = 0;
String output = "";
String[] finalOutput = new String[1000];
sendToProcessView("Unix Command: " + command);
run = Runtime.getRuntime().exec(command);
run.waitFor();
sendToProcessView("In Unix Command");
if (boolOutput == true){
sendToProcessView("In Output Mode of Unix Command");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(run.getInputStream()));
sendToProcessView("Passed Buffer Reader");
while ((output = stdInput.readLine()) != null) {
sendToProcessView("Output: " + output);
finalOutput[i] = output;
i++;
}
}
return finalOutput;
}
run.waitFor()after you have consumed the command’s output, not before.