In a controlled intranet environment, executing external programs from a PHP application can be a challenge. While commands like system and exec can launch processes, they face difficulties handling programs with a visible user interface.
The Problem:
The user is able to start programs that operate silently (e.g., "echo hello > hello.txt"). However, attempts to launch programs with a graphical user interface (e.g., "explorer") result in no action.
The Solution:
To resolve this issue, it's necessary to allow the Apache service running the PHP script to interact with the desktop:
Code Snippets:
After making these changes, you can now launch GUI programs from PHP using pclose and system:
Non-Blocking:
<code class="php">pclose(popen("start /B notepad.exe", "r"));</code>
Blocking:
<code class="php">system('start notepad.exe');</code>
Note:
This solution is tested on Windows XP and may not work on other Windows versions.
The above is the detailed content of How to Execute External Programs with PHP with User Interface in a Controlled Intranet Environment?. For more information, please follow other related articles on the PHP Chinese website!