[英]Launch interactive ssh from nodejs
I have a text blob that contains ip, port, user and passord and would like to write a small utility script where I can: 我有一个包含ip,port,user和passord的文本blob,我想写一个小实用程序脚本,我可以:
How would I launch the ssh command from node with the arguments, exit node and continue on ssh'ing? 如何从带有参数的节点启动ssh命令,退出节点并继续ssh'ing? The documentation I've found regarding ie child_process concerns launching and controlling the process within node, but I simply want to exit back and take over once ssh is started.
我发现的关于ie child_process的文档涉及在节点内启动和控制进程,但我只想退出并在ssh启动后接管。
The following code will fit your requirements, adjust it to your needs. 以下代码符合您的要求,根据您的需求进行调整。 The program does the following:
该计划执行以下操作:
port
from a file port
stdin
stdin
读取数据 ssh
using child_process.fork
child_process.fork
启动ssh
Code: 码:
var port = require('fs').readFileSync('port.txt');
const rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter hostname: ', (answer) => {
require('child_process').spawn('ssh', [answer, port],
{stdio: [process.stdin, process.stdout, process.stderr]});
});
The question is answered except for the following point: 除了以下几点之外,问题得到解答:
exit node and continue on ssh'ing
退出节点并继续ssh'ing
I am not aware of this being possible in any programming language, but a better answer can correct me. 我不知道任何编程语言都有可能,但更好的答案可以纠正我。 Instead, you launch a child process and redirect all input/output to it.
相反,您启动子进程并将所有输入/输出重定向到它。 From your perspective, you only interact with
ssh
, so the fact that the node
process still exists as a parent to ssh
is transparent to you. 从您的角度来看,您只与
ssh
交互,因此node
进程仍然作为ssh
的父进程存在这一事实对您来说是透明的。
An equivalent command in perl
for example would be system("ssh");
例如,
perl
的等效命令是system("ssh");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.