nodejs exec ssh 挂起

ahl*_*lev 5 ssh node.js

我希望我的 Nodejs 应用程序执行一行命令并退出。该命令用于在远程计算机上创建远程端口转发。

const exec = require("child_process").exec;

let script = "ssh -i cert.pem ubuntu@ec2 -R 9000:localhost:22 -S /tmp/.ssh-ec2 -M -fN ssh-ec2";

exec(script, (error, stdout, stderr) => {
      console.debug(stdout);
});
Run Code Online (Sandbox Code Playgroud)

节点测试.js

它挂在那里;但如果我在终端中运行纯命令。

ssh -i cert.pem ubuntu@ec2 -R 9000:localhost:22 -S /tmp/.ssh-ec2 -M -fN ssh-ec2

它退出了。

我想念什么?

Sco*_*ott 1

我能够通过传递"ignore"stdio child_process 提供的配置选项来开始工作,如下所示:

execSync(sshTunnelCommand, { stdio: 'ignore' });
Run Code Online (Sandbox Code Playgroud)

根据他们的文档中的行尝试了这一点:

如果不消耗输出,请使用 { stdio: 'ignore' } 选项