简体   繁体   English

PHP exec()函数

[英]PHP exec() function

I developed a program on windows xp and I used exec to run a ".bat" file and it worked fine. 我在Windows XP上开发了一个程序,并使用exec运行了一个“ .bat”文件,并且运行良好。 I copied the exact program on windows 2003 and the bat file didn't run. 我在Windows 2003上复制了确切的程序,但bat文件没有运行。 I used echo before the exec function and it seemed to work fine, I mean it echoed : 我在exec函数之前使用过echo,它似乎可以正常工作,我的意思是它echoed:

D:\\xampp\\htdocs\\x>RunDLL32.EXE printui.dll,PrintUIEntry /y /n "HP LaserJet P2015 Series PS" D:\\ xampp \\ htdocs \\ x> RunDLL32.EXE printui.dll,PrintUIEntry / y / n“ HP LaserJet P2015 Series PS”

but it didn't do anything. 但是它什么也没做。 I ran the bat file alone and it worked fine. 我只运行了bat文件,效果很好。 Just doesn't work with exec in windows 2003. any ideas? 只是在Windows 2003中不能与exec一起使用。有什么想法吗?

Is safe mode enabled on that server? 该服务器上是否启用了安全模式? If so then you won't be able to execute programs like that. 如果是这样,那么您将无法执行此类程序。 You either need to turn safe mode off or add that directory to the safe_mode_exec_dir in PHP.ini 您需要关闭安全模式或将该目录添加到PHP.ini中的safe_mode_exec_dir

From the manual 从手册

Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. 注意:启用安全模式后,您只能在safe_mode_exec_dir中执行文件。 For practical reasons, it is currently not allowed to have .. components in the path to the executable. 出于实际原因,当前不允许在可执行文件的路径中包含..组件。

If you are using IIS, in order to execute an application the Internet Guest account needs execute rights on CMD.exe . 如果使用IIS,则为了执行应用程序,Internet Guest帐户需要对CMD.exe执行权限。 As every shell execute is run as CMD.exe -c <your command> . 由于每个shell执行都是以CMD.exe -c <your command>

Then verify that a simple echo system("dir"); 然后验证一个简单的echo system("dir"); works. 作品。 This should return the directory listing of the current folder. 这应该返回当前文件夹的目录列表。

It is also likely you will have to give the Internet Guest account execute rights to the batch file, and any executable it executes (in this case rundll32.exe ). 您也可能必须授予Internet Guest帐户对该批处理文件及其执行的任何可执行文件的执行权(在本例中为rundll32.exe )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM