doushang7209
2015-12-07 20:52
浏览 86
已采纳

从php脚本打开gnome-terminal

I want to try to open gnome-terminal from php script:

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. With my own socket. nginx and socket use my user and not www-data. (I'm on ubuntu 14.04LTS)

I've try 0777 rights...

My bash script can run from netbeans IDE ans terminal... but not from php...

图片转代码服务由CSDN问答提供 功能建议

我想尝试从php脚本打开gnome-terminal:

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

这个脚本使用一个函数来检查终端:< / p>

  SCRIPTCURRENT =`readlink -m $ 0` 
SCRIPTCURRENTPATH = $(dirname“$ SCRIPTCURRENT”)
 
nunintoterminal(){
 if!  [-t 1]; 然后
 gnome-terminal -e“bash $ 1”
退出0 
 fi 
} 
nunintoterminal $ SCRIPTCURRENT 
   
 
 

我试过:

  shell_exec('gnome-terminal'); 
   
 
 

但它不起作用...(我知道 它可能......)但是如何?

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

我尝试了0777权限...

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

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjie5570 2015-12-07 21:48
    已采纳

    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 $1" 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');
    

    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
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题