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

3 Answers 3

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

2
  • Yes that's to see what would get executed but it doesn't show anything.
    – Chirag
    Feb 3, 2011 at 8: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! Feb 3, 2011 at 8: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

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");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.