I am running a java program on Windows that collects a log from Windows events. A .csv file is created on which certain operations must be performed.
Commands are executed and transmitted through channels. How can I make my Java program wait for the process to complete?
Here is the code snippet I'm using:
Runtime commandPrompt = Runtime.getRuntime(); try { Process powershell = commandPrompt.exec("powershell -Command \"get-winevent -FilterHashTable @{ logname = 'Microsoft-Windows-PrintService/Operational';StartTime = '"+givenDate+" 12:00:01 AM'; EndTime = '"+beforeDay+" 23:59:59 '; ID = 307 ;} | ConvertTo-csv| Out-file "+ file +"\""); //I have tried waitFor() here but that does not seem to work, required command is executed but is still blocked } catch (IOException e) { } // Remaining code should get executed only after above is completed.
java process exec
user1631171
source share