通过 PHP 执行命令的帮助
我正在尝试运行 PHP exec 命令。它在我的 CMD 中运行起来就像一个魅力,但当我通过 PHP 尝试它时它没有做任何事情。有人可以看到我在这里做错了什么吗?
谢谢。
<?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
?>
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
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
exec
调用中的内容与命令注释中的内容不同。您删除了命令及其参数周围的引号。它们可能很重要。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.在 Windows 中,exec() 发出对“cmd /c your_command”的内部调用。这意味着您的命令必须遵循 cmd.exe 施加的规则,其中包含完整命令周围的一组额外引号。希望这些链接会有帮助
http://php.net/manual/en/function.exec .php
http://ss64.com/nt/cmd.html
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
当您执行两个或更多命令时,必须将它们分开
试试这个:
when you execute two or mor commands you must seperate them
try this: