从 php 脚本打开 gnome 终端

Open gnome-terminal from php script

我想尝试从 php 脚本打开 gnome 终端:

shell_exec('bash /data/manager/application/.shell/system.sh');

此脚本使用一个函数来检查终端:

SCRIPTCURRENT=`readlink -m [=12=]`
SCRIPTCURRENTPATH=$(dirname "$SCRIPTCURRENT")

runintoterminal () {
    if ! [ -t 1 ]; then
        gnome-terminal -e "bash "
        exit 0
    fi
}
runintoterminal $SCRIPTCURRENT

我试过:

shell_exec('gnome-terminal');

但这行不通...(我知道这是可能的...)但是如何呢?

我使用 nginx 和 php-fpm。用我自己的插座。 nginx 和套接字使用我的用户而不是 www-data。 (我在 ubuntu 14.04LTS)

我试过0777权限...

我的 bash 脚本可以 运行 来自 netbeans IDE ans 终端...但不能来自 php...

The problem is most likely that gnome-terminal doesn't know where it should draw itself. Normally it shows up on the same display as the program that launched it (IDE, terminal), but web servers don't have displays so it doesn't know where to go. You can try DISPLAY=:0 gnome-terminal -e "bash " to show it on the current first local graphical login session, if it has permissions for that. that other guy

shell_exec('DISPLAY=:0 bash /data/manager/application/.shell/system.sh');

或函数:

SCRIPTCURRENT=`readlink -m [=11=]`
SCRIPTCURRENTPATH=$(dirname "$SCRIPTCURRENT")

runintoterminal () {
    if ! [ -t 1 ]; then
        DISPLAY=:0 gnome-terminal -e "bash "
        exit 0
    fi
}
runintoterminal $SCRIPTCURRENT