怎样在网页中显示ssh2_exec得到的结果?

蜜莉恩 蜜莉恩 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
前几天发过个帖子关于php 的ssh2功能,我的目的是想要通过php代码连接远程服务器,运行某条指令然后返回结果,然后在网页中显示结果。
现在的问题是结果可以正确返回,但网页显示不了
我的代码如下,文件名是demo.php:
$name = "myserver.com";
function get_host_list($name)
{
$connection = ssh2_connect($name,22);
ssh2_auth_password($connection, 'root','changeme');
$sftp = ssh2_sftp($connection);

$stream = ssh2_exec($connection, 'python file.py');
stream_set_blocking($stream, true);
// Return the result and delete the files
$host_list = stream_get_contents($stream);

return $host_list;
}
echo get_host_list($name);


如果在shell中运行代码
php demo.php,结果可以正确显示。
但如果我在浏览器中打开此文件
www.path/to/the/file.demo.php
则不显示任何东西。。

为什么shell中可以显示结果但网页中就现实不了呢??
个人猜测是不是因为当网页已经load了,但结果还没返回过来,所以没有东西可以显示?

请大虾帮忙解决,急~ 谢谢
...全文

相关推荐

node-ssh2-exec:SSH2登录和执行的节点插件

节点-ssh2-exec SSH2登录和执行的节点插件 如何使其运作? cd节点-ssh2-exec / npm安装 这个怎么运作? # # Run command "node shell.js" inside the app folder & provide the necessary details required # to login into the server. Username & hostname are required fields. # > node shell.js Deployment Engine Node Plugin for SSH2. Usage: /usr/local/bin/node shell.js --options... Options: -u, --username, --user SSH Login Usernam

zhuyurrr

用paramiko:ssh.exec_command怎样运行import命令

各位大神,搭救搭救老弟~~ 我用ssh.exec_command(comm)运行py文件,问题是我的py文件import了很多东西。 这里我看了网上说exec调用有着类似于import的效果,但是,它从技术上不会导入模块,默认情况下,每次以这种方式调用 exec的时候,它都重新运行文件, 就好像我们把文件粘贴到了调用exec的地方 。因此, exec不需要在文件 修改后进行模块重载 ,它忽略了常规的模块导入逻辑。 https://blog.csdn.net/fhd001/article/details/6753013 也有大佬遇到过类似问题:https://stackoverflow.com/

weixin_38637918

ssh-exec, 使用 node.js 在ssh上执行脚本.zip

ssh-exec, 使用 node.js 在ssh上执行脚本 ssh在ssh上执行脚本,使用 node.js 和管道,并从可以通过npm提供。npm install ssh-exec它是用普通的Javascript编写的,使用了 ssh2作为所有重。用法var ex

weixin_38744270

windows平台上采用libssh2开发的SSH

使用libssh2开发的一个SSH,终于写好了,分享给大家。

cuitboy1

node-ssh-exec:一个简单的 ssh2 包装器,用于使用 Node.js 通过 ssh 在遥控器上执行 shell 命令

节点-ssh-exec 一个简单的 ssh2 包装器,用于使用 Node.js 通过 ssh 在遥控器上执行 shell 命令。 安装 npm install node-ssh-exec 用法 var exec = require ( 'node-ssh-exec' ) ; var // see https://github.com/mscdex/ssh2 config = { host : 'localhost' , username : 'root' , password : 'root' } , command = 'ls -alh' ; exec ( config , command , function ( error , response ) { if ( error ) {

Untournant
评论 4
收藏 已收藏
分享
返回顶部
蜜莉恩
基础编程 21,889 成员 140,329 内容