How do I to properly handle spaces in PHP Shell_exec?
问题 I'm running on win2003 server, PHP 526, via the cmd-line. I have a cmdline string: $cmd = ' "d:\Prog Files\foo.exe" -p "d:\data path\datadir" '; Trying to do this in php code $out = `$cmd`; # note use of backticks AKA shell_exec results in a failure by foo.exe as it interprets the -p arg as "d:\data". However, the same $cdm string copied to the windows shell cmdline executes successfully. How do I properly handle spaces in PHP shell_exec ? 回答1: Use escapeshellarg() to escape your arguments,