简体   繁体   中英

Execute gnome-terminal from remote server

Alright, so I have a VPS running with gnome-terminal, and I'm using the following php script execute commands on the remote server.

<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('IP address');
if (!$ssh->login('root', 'rthtrhtrhrthrthrth')) {
    exit('Login Failed');
}

echo $ssh->exec('gnome-terminal -e java -jar run.jar --window-with-profile=b1dcc9dd-5262-4d8d-a863-c897e6d979b9');
?>

Which when I run the script I get the following error

** (gnome-terminal:1952): WARNING **: Could not open X display Failed to parse arguments: Cannot open display:

I'm trying to get it to run a command from a remote server which will execute in gnome-terminal and open the jar file. Pretty much when the shell command is executed on my remote server, connects to ssh and runs the gnome-terminal command to open up a desktop application on that VPS.

Is this possible or am I doing something wrong?

UPDATE

In Putty I've gotten it to work by issueing the following commands

export DISPLAY=:1
gnome-terminal -e "java -jar file.jar"

But still trying to execute it with my web server using

<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('IP address');
if (!$ssh->login('root', 'rthtrhtrhrthrthrth')) {
    exit('Login Failed');
}
echo $ssh->exec('export DISPLAY=:1');
echo $ssh->exec('gnome-terminal -e "java -jar run.jar"');
?>

I'm still getting the error where it cannot open X display. I'm only trying to pass this to the VPS, not display anything on the web server

Does the VPS have an X running ? I would suggest a slightly different approach: Rather than running gnome-terminal, you might as well execute stuff directly using ssh. Bare in mind that your php will hang until java is finised. Add a "&" at the end of your command if you want it detached from ssh.

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.

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