1

I'm trying to run a PHP exec command. It runs like a charm in my CMD but it doesn't do anything when I try it via PHP. Can someone see what I'm doing wrong here.

Thanks.

<?php

//Command line command
//"C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" "C:\inetpub\wwwroot\dev_site\images\0000\thumbs.php"
//This runs perfectly fine.

echo "Command line execution started<br />";
//This is when $desination is already set to 0000
echo  exec("C:\\Program Files (x86)\\PHP\\v5.3\\php-cgi.exe C:\\inetpub\\wwwroot\\dev_site\\images\\$destination\\thumbs.php");
echo "<br />Command line command successful";
//Does not run
?>
Chirag
  • 1,919
  • 6
  • 25
  • 33
  • Related, [How do you run a .bat file from PHP?](http://stackoverflow.com/q/835941) – jww Nov 15 '16 at 04:02

3 Answers3

6

What's in your exec call is not the same as what's in your comment as the command. You got rid of the sets of quotes around the command and its argument. They may have been important.

missing quotes

Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
  • Yes that's to see what would get executed but it doesn't show anything. – Chirag Feb 03 '11 at 08:11
  • 4
    Reread -- the command you're executing is not the same as the one you wanted to execute. You lost two sets of double quotes. Put them back in! – Dan Grossman Feb 03 '11 at 08:13
1

In Windows, exec() issues an internal call to "cmd /c your_command". This implies that your command must follow the rules imposed by cmd.exe which includes an extra set of quotes around the full command. Hope these links will be helpful

http://php.net/manual/en/function.exec.php

http://ss64.com/nt/cmd.html

gsk
  • 1,685
  • 1
  • 13
  • 19
1

when you execute two or mor commands you must seperate them
try this:

echo  exec("C:\\Program Files (x86)\\PHP\\v5.3\\php-cgi.exe", "C:\\inetpub\\wwwroot\\dev_site\\images\\$destination\\thumbs.php");
ratlink
  • 11
  • 1