This is working on my Windows 10 system, but I'm very skeptical as to whether it will also work on Linux and macOS. I want to ensure that it does, because it's incredibly useful to be able to run commands to open various applications from the localhost "web control panel". I do it all the time, but don't have a Mac or a Linux PC for testing.
Steps to reproduce:
Make sure that you're running the built-in PHP webserver and not something else.
Create a file called test.php
with this content and put it in your WWW root:
if (isset($_GET['run'])) shell_exec('winver'); echo '<p><a href="?run=1">test me</a></p>';
Obviously change the "winver" part to a command that macOS or Linux will understand. As long as it brings up some kind of GUI window when run.
http://127.0.0.1/test.php
and click the hyperlink. Does this happen on macOS and Linux, or is this a "lucky coincidence" that just happens to work on Windows but wasn't intended?
I've just tested this and successfully launched Microsoft Word on macOS and xcalc on Linux.
You do have to be careful that the user the web server is running has has access to the desktop (eg in Linux you need to have DISPLAY
set correctly etc) but that isn't an issue if you are using php -S
on the same desktop you want to display the GUI application on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.