---
title: "exec doesn't execute command if path contains whitespaces"  
description: "exec doesn't execute command if path contains whitespaces"  
author: "Manoj Bhatt"  
published: 2013-05-10  
updated: 2013-05-10  
canonical: https://www.mindstick.com/forum/859/exec-doesn-t-execute-command-if-path-contains-whitespaces  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# exec doesn't execute command if path contains whitespaces

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
When I do something like\
exec("c:\\[Program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) [Files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud) (x86)\\wkhtmltopdf\\wkhtmltopdf.exe --footer-center as http://bbc.co.uk c:\\test2.pdf",$[output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular));nothing happens. [File exists](https://www.mindstick.com/forum/33389/how-do-i-check-if-a-file-exists-in-java) and the following line returns 1.\
[echo](https://www.mindstick.com/articles/23392/be-a-21st-century-shopper-and-use-your-amazon-echo-for-holiday-shopping) 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](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why). Can that be fixed?\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

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.


---

Original Source: https://www.mindstick.com/forum/859/exec-doesn-t-execute-command-if-path-contains-whitespaces

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
