![](/img/trans.png)
[英]Display more than 17 lines using phpseclib Interactive shell
[英]Using phpseclib with a custom shell wrapper
我正在使用PHPSeclib訪問安裝了dokku-alt的服務器:
http://dokku-alt.github.io/how-it-works.html
通過遵循一個典型示例,我設法將命令發送到我帳戶上的自定義外殼程序:
$ssh=$this->connect();
echo trim($ssh->exec("version");
這相當於
ssh dokku@my.node.org version
並按預期工作。 但是,如果我嘗試執行一個期望我通過STDIN發送數據的命令,則會出現問題。 據Net_SSH2文件,我需要write
數據到SSH流,而不是使用EXEC()。 不幸的是,我的下一個示例不起作用,因為自定義外殼程序不接收任何參數,並以幫助頁面作為響應:
$ssh=$this->connect();
$ssh->write("mysql mariadb:console myapp newdb\n");
$ssh->write("show tables\n");
$ssh->read('[prompt]');
其結果與
ssh dokku@my.node.org
它只是以幫助頁面作為響應。
如何結合“ exec”功能並且仍然能夠寫入數據? 這樣的事情也不起作用:
$ssh=$this->connect();
$ssh->exec("mysql mariadb:console myapp newdb");
$ssh->write("show tables\n");
$ssh->read('[prompt]');
謝謝。
我認為您正在尋找PTY模式? 例如。
$ssh->enablePTY();
$ssh->exec('mysql mariadb:console myapp newdb');
echo $ssh->read('mysql>');
$ssh->write("show tables\n");
echo $ssh->read('mysql>');
更多信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.