What are the potential issues when using the PHP exec function to call external programs like Open Office?

One potential issue when using the PHP exec function to call external programs like Open Office is security vulnerability, as it opens up the possibility of command injection attacks. To mitigate this risk, it is recommended to use escapeshellarg() or escapeshellcmd() to properly escape the command arguments before passing them to exec.

$filename = escapeshellarg('document.docx');
$outputFile = escapeshellarg('output.pdf');
exec("soffice --headless --convert-to pdf $filename --outdir /path/to/output/folder");