NodeJs 套接字连接问题
NodeJs Socket Connection Issue
我正在尝试连接到远程计算机上运行的进程。我已经使用 ssh2 连接到删除机器。现在我正在尝试连接到机器中运行的进程。进程名称为 dd_servicesc
c.exec('OmneBabble dd_servicesc',function(){}
我使用上面的代码命令连接到进程。在连接上,我想执行一系列连接。但是目前的问题是,如果我再次使用 c.exec,下一个命令会在进程之外执行,因此返回权限被拒绝。为了更好地理解,请查看以下内容
OmneBabble dd_servicesc
>0 1 om_get_user_info 31003 1 MACLEAN1-11365
这里的初始命令是 OmneBabble dd_servicesc,其中需要执行 0 1 om_get_user_info 31003 1 MACLEAN1-11365。请指出我可以参考的任何链接,以找到解决此问题的方法。
问候
麦克莱恩
Update
function ssh()
{
var Connection = require('ssh2');
var c = new Connection();
c.on('connect', function() {
console.log('Connection :: connect');
});
c.on('ready', function() {
console.log('Connection :: ready');
c.exec('OmneBabble dd_servicesc', function(err, stream) {
if (err) throw err;
stream.on('data', function(data, extended) {
console.log((extended === 'stderr' ? 'STDERR: ' : 'STDOUT: ')
+ data);
});
stream.on('end', function() {
console.log('Stream :: EOF');
});
stream.on('close', function() {
console.log('Stream :: close');
});
stream.on('exit', function(code, signal) {
console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
c.end();
});
});
c.exec('0 1 om_get_user_info 31003 1 MACLEAN1-11365', function(err, stream) {
if (err) throw err;
stream.on('data', function(data, extended) {
console.log((extended === 'stderr' ? 'STDERR: ' : 'STDOUT: ')
+ data);
});
stream.on('end', function() {
console.log('Stream :: EOF');
});
stream.on('close', function() {
console.log('Stream :: close');
});
stream.on('exit', function(code, signal) {
console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
c.end();
});
});
});
c.on('error', function(err) {
console.log('Connection :: error :: ' + err);
});
c.on('end', function() {
console.log('Connection :: end');
});
c.on('close', function(had_error) {
console.log('Connection :: close');
});
c.connect({
host: '192.168.20.204',
port: 22,
username: 'oaa',
password: 'marigold'
});
}
exports.ssh = ssh;
更新:在这里 OmneBabble dd_services连接到套接字,即> dd_services。
之后,我们将使用 0 1 om_get_user_info 31003 1 MACLEAN1-11365 发布对套接字的请求
然后,套接字会将请求发布到其所有客户端进程。最后,接受请求的客户端进程将使用输出进行响应。所以我不能使用子进程将父进程的输出映射到子进程。
连接到进程,但如果进程本身是通过node
启动的,你可以用child_process.spawn
启动它们,在那里你得到一个对象,可以设置stdout
、stderr
和stdin
,以及向进程发送信号。
编辑:
查看附加的代码,似乎您希望通过 stdin(标准(将第二个命令发送到进程,而不是执行另一个命令。您也许可以将第二个命令作为初始可执行文件通过管道传输到主进程中:
c.exec('echo "0 1 om_get_user_info 31003 1 MACLEAN1-11365" | OmneBabble dd_servicesc', function...
我已经能够用 ssh2 运行交互式 shell
。c.shell(function(err, stream) {
if (err) throw err;
stream.on('data', function(data, extended) {
console.log((extended === 'stderr' ? 'STDERR: ' : 'STDOUT: ')
+ data);
});
// below code to connect stdin to the remote shell
process.stdin.resume();
process.stdin.on('data', function (data) {
allowed = false;
stream.write(data);
尝试在 exec 语句后插入 STDIN 重定向。
我学会了如何从这个已关闭的问题中重定向 STDIN:https://github.com/mscdex/ssh2/issues/94
- Javascript连接元素,出现问题
- 在html中连接图像和描述时出现问题
- 将.schie Javascript函数连接到我的HTML时出现问题
- ASP.NET-连接html、javascript和CSS的问题
- NodeJs 套接字连接问题
- 使用JavaScript连接字符串有什么问题
- 检测 iframe 中的连接问题
- 以下jQuery字符串连接代码有什么问题
- 使用 sequelize ORM 连接到节点上的 Amazon RDS Postgres 数据库.js出现问题
- 加载资源时出现 OpenTok JS 连接超时问题
- JavaScript 谷歌地图折线 :连接所有给定的 GPS 位置时出现问题
- 使用 grunt requirejs 与单个大型缩小文件连接缓慢时加载问题
- Node 和 MySQL - 解决“连接过多”问题
- 实时连接小程序问题
- NodeJS MongoDB 连接字符串问题
- 使用IONIC的IOS没有网络连接功能问题
- Windows Live API连接问题
- LinkedIn API 连接问题
- webrtc通过websocket客户端/服务器连接问题
- 流程图问题连接条形图和线形图