I'm working on a project and I'm having problems with it, this program I'm posting is similar to what I'm working on.
The problem is this: it arrives at while
, the program does its job, then hangs up and does not exit.
I have tried everything. Could anyone give any suggestions?
public class CommandZ {
private static String Command;
private static Scanner scan;
public static void main(String[] args) {
scan = new Scanner(System.in);
System.out.println("Shell: ");
Command = scan.nextLine();
ProcessBuilder pb = new ProcessBuilder("powershell.exe", "-Command", Command);
Process p;
try {
p = pb.start();
} catch (IOException e) {
System.out.println("Failed to start powershell");
return;
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
System.out.println("Begin!");
try {
//PROBLEMA AQUI
while((line = bufferedReader.readLine()) != null){
System.out.println(line);
//Imprimi as linhas, e não da sequência no programa..
}
} catch (IOException e) {
System.out.println("Failed to read line");
return;
}
System.out.println("Exit");
}