I'm trying to run a powershell command (get status from printer) in intellij but for some reasons it doesn't run from the java. The program does not give an error and just delayed. Maybe i have not some access, but I don't know which one.
In CMD this command work correctly.
public static void main(String[] args) {
String printerName = "HP LaserJet 1022n";
ProcessBuilder builder = new ProcessBuilder("powershell.exe", "get-wmiobject -class win32_printer | Select-Object Name,Status | where {$_.Name -eq '" + printerName + "'}");
String fullStatus = null;
Process reg;
builder.redirectErrorStream(true);
try {
reg = builder.start();
fullStatus = IOUtils.toString(reg.getInputStream(), "UTF-8"); //in this moment program is delaying
reg.destroy();
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.print(fullStatus);
}