简体   繁体   English

从 php 脚本打开 gnome-terminal

[英]Open gnome-terminal from php script

I want to try to open gnome-terminal from php script:我想尝试从 php 脚本打开 gnome-terminal:

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

This script use a function to check terminal:此脚本使用一个函数来检查终端:

SCRIPTCURRENT=`readlink -m $0`
SCRIPTCURRENTPATH=$(dirname "$SCRIPTCURRENT")

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

I've tried:我试过了:

shell_exec('gnome-terminal');

But it's doesn't work... (I know it's possible...) But how to ?但它不起作用......(我知道这是可能的......)但是如何?

I use nginx and php-fpm.我使用 nginx 和 php-fpm。 With my own socket.用我自己的插座。 nginx and socket use my user and not www-data. nginx 和套接字使用我的用户而不是 www-data。 (I'm on ubuntu 14.04LTS) (我在 ubuntu 14.04LTS 上)

I've try 0777 rights...我已经尝试了 0777 权利...

My bash script can run from netbeans IDE ans terminal... but not from php...我的 bash 脚本可以从 netbeans IDE ans 终端运行...但不能从 php...

The problem is most likely that gnome-terminal doesn't know where it should draw itself.问题很可能是 gnome-terminal 不知道它应该在哪里绘制自己。 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.通常,它与启动它的程序(IDE、终端)显示在同一显示器上,但 Web 服务器没有显示器,因此它不知道去哪里。 You can try DISPLAY=:0 gnome-terminal -e "bash $1" to show it on the current first local graphical login session, if it has permissions for that.您可以尝试 DISPLAY=:0 gnome-terminal -e "bash $1" 在当前第一个本地图形登录会话中显示它,如果它有权限的话。 that other guy 那个家伙

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

Or on function:或在功能上:

SCRIPTCURRENT=`readlink -m $0`
SCRIPTCURRENTPATH=$(dirname "$SCRIPTCURRENT")

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

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

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