Java: wait for exec process till it exits <p>Hi I am running a java program in windows that collects log from windows events. A csv file is created on which certain operations are to be performed. The command execed is a piped one so how do i make java program to wait until the process is finished. Here is the code snippet i am using</p> <pre><code>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. </code></pre> <p>Any help on this is greatly appreciated. Thanks in advance</p>