PHP shell_exec不适用于gnome

In a terminal window running alert 9 gives me a popup saying 9

However, running alert 9 in shell_exec gives nothing.


What should I be aware of?

Just to mention: other commands work neither that interact with the GUI. I am using gnome 3.16.3


UPDATE

My concrete goal is to run an xdotool command using the gnome environment. ( xdotool key ctrl+shift+u )

alert is not a command, but an alias for notify-send. Aliases are loaded only in interactive shell, so it is not the best choice to test shel_exec.

These 2 command work well with php-cli:

$ php -r "shell_exec('notify-send 9');"
$ php -r "shell_exec('xdotool key ctrl+shift+u');"

The first one pops the 9 in notification area, and the last one output underscored 'u'.

Apache with mod_php is a daemon, subprocess of init, which knows nothing about xserver. If, for example, you run php built-in web server from a terminal within xserver like $ php -S 0:8080 it works as expected.

I believe PHP is launching a shell that isn't aware of your X11 environment and you need to set the $DISPLAY environment variable. Try the following modification to your shell_exec:

shell_exec("DISPLAY=\":0\" alert 9");

alert is not a standard command, at least on RedHat, Solaris and AIX, so you have to mention it in your question that it's a proprietary command/program

Your alert script/program does'nt consider to flush text data in standard or file output, so you can't do any redirection using pipe |, or redirect >, and finally, the php function shell_exec() can catch anything

Maybe you can redirect graphic data (i'm not sure) but generally, it's used by the graphic server