EXEC DOESN'T EXECUTE COMMAND IF PATH CONTAINS WHITESPACES

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
PHP 
PHP
 1610  View(s)
Ratings:
Rate this:
Hi Expert!

When I do something like

exec("c:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe --footer-center as  http://bbc.co.uk c:\\test2.pdf",$output);
nothing happens. File exists and the following line returns 1.

echo file_exists("c:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe");
If I change it

 exec("d:\\wkhtmltopdf\\wkhtmltopdf.exe --footer-center as  http://bbc.co.uk c:\\test2.pdf",$output);
works fine. Can that be fixed?

Thanks in advance! 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: exec doesn't execute command if path contains whitespaces

    Hi Manoj!

    You need to quote your executable's path or escape the white space. Either:

    exec("c:\\Program^ Files^ (x86)\\wkhtmltopdf\\wkhtmltopdf.exe --footer-center as  http://bbc.co.uk c:\\test2.pdf",$output);
    or

    exec("\"c:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe\" --footer-center as  http://bbc.co.uk c:\\test2.pdf",$output);
    will work.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!