I am trying to establish an interactive SSH connection to a remote server using PHP via the command line in Mac OS X 10.6. I am currently using the PHP proc_open function to execute the following command:
ssh -t -t -p 22 user@server.com
It almost works. The parameters are supposed to -t -tforce a pseudo-terminal, which they almost do. I can enter the SSH password and press enter. However, after clicking enter a terminal that just freezes. There is no output, there is nothing - it is as if the SSH session failed. I can’t run commands or anything else and have to kill it all using Ctrl + C. I know that login is successful, because I can execute a command like ssh -t -t -p 22 user@server.com "ls -la"and get the correct output.
I thought the problem should be due to the fact that I used standard channels in my proc_open call, so I replaced them with pty. I get the following error: "pty pseudo-terminal is not supported on this system ..."
Mac OS X just doesn't support pty or pseudo terminals? (I'm new to using all this shell terminology).
Here's the PHP code:
$descriptorspec = array(0 => array("pty"), 1 => array("pty"), 2 => array("pty"));
$cwd = getcwd();
$process = proc_open('ssh -t -t -p 22 user@server.com', $descriptorspec, $pipes, $cwd);
if (is_resource($process))
{
while (true)
{
echo(stream_get_contents($pipes[1]));
$status = proc_get_status($process);
if (! $status["running"])
break;
}
}
(Sorry - I can’t figure out the instructions for formatting SO for life ...)
What am I doing wrong? Why can't I use pty? Is it just not possible on Mac OS X? Thank you for your help!
source
share