Libreoffice Headless Wait for Completion

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

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

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.