Oleksandr IY
Oleksandr IY

Reputation: 3146

exec doesn't execute command if path contains whitespaces

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 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?

Upvotes: 1

Views: 4745

Answers (2)

enenen
enenen

Reputation: 1967

If I remember properly you can use double quotes when you have whitespaces in a path name or a file name.

For example:

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

Upvotes: 2

Prisoner
Prisoner

Reputation: 27628

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.

Upvotes: 1

Related Questions