I'm trying to use the ssh2 functions to run a graphical app. I have no
problem opening ssh2_shell and running something like "/bin/ls /tmp".
However when I try to do something like:
fwrite($stdio,"/usr/X11R6/bin/xclock -display some-other-machine:0\n");
It doesn't work. I've tried wrapping the xclock command in a shell
script and a C program and still no luck. In both instances I can ssh
into the remote machine and run the commands just fine. Is this
something that just doesn't work? Or does someone have a tip for how
to get that to display back? Should I be looking at ssh2_exec?
-Brian Vincent
Full code below using some sample PHP code:
<?php
echo "Connexion SSH ";
if (!($resource=@s sh2_connect("10 .72.xx.xx"))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";
// Authentificatio n by login/passwd
echo "Authentificati on ";
if (!@ssh2_auth_pa ssword($resourc e,"myusername", "mypassword ")) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";
// We need a shell
echo "Shell stdio ";
if (!($stdio = @ssh2_shell($re source,"xterm") )) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";
// Execution of any command
// Be careful to add an '\n' at the end of the command
$command = "/usr/X11R6/bin/xclock -display
some-other-machine:0\n";
fwrite($stdio,$ command);
// IMPORTANT
// For some obscur reasons, just after ur command, u need to
make a sleep to be sure, that the command has reached the server and is
running
sleep(1);
// Then u can fetch the stream to see what happens on stdio
while($line = fgets($stdio)) {
flush();
echo $line."<br />";
}
// It's always cleaner to close all stream
fclose($stdio);
?>