Home > DeveloperSection > Forums > exec doesn't execute command if path contains whitespaces
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    May-10-2013 2:38 AM

 PHP PHP 
Ratings:


 1 Reply(s)
 1273  View(s)
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! 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-10-2013 9:15 AM

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.

Don't want to miss updates? Please click the below button!

Follow MindStick