Java: дождитесь exec процесса, пока он не выйдет

Я запускаю Java-программу в Windows, которая собирает журнал событий Windows. Создается файл .csv, для которого необходимо выполнить определенные операции.

Команды исполняются и передаются по каналу. Как я могу заставить мою программу Java ждать, пока процесс не закончится?

Вот фрагмент кода, который я использую:

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.

Ответы на вопрос(3)

Ваш ответ на вопрос