libreoffice headless wait for completion

I'm converting word files to pdf files using soffice (on windows with powershell).

Calling the following code works pretty well:

$soffice = "C:\Program Files (x86)\LibreOffice 5\program\soffice.exe"
& $soffice --convert-to pdf "c:\temp\somefile.docx" --headless --outdir c:\temp

However, the command exits immediately, before the pdf is actually created.

Is there anyway to wait for completion, before returning to the prompt?

I fear that batching multiple conversion spawn dozen of process and saturates the computer.

1 Answer

I found the solution. I simply have to spawn the process using Start-Process specifying to wait for completion:

 Start-Process -FilePath $soffice ` -ArgumentList "--convert-to pdf ""c:\temp\somefile.docx"" --headless --outdir c:\temp" ` -Wait

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like