nodejs exec ssh hangs

Viewed 224

I want my nodejs app to execute a line of command and exit. The command is used for creating a remote port forwarding on a remote machine.

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);
});

node test.js

It hangs there; but if I run pure command in terminal.

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

It exits.

What do I miss?

1 Answers

I was able to get working by passing "ignore" to stdio config option provided by child_process like so:

execSync(sshTunnelCommand, { stdio: 'ignore' });

Tried this based on the line from their docs reading:

Use the { stdio: 'ignore' } option if the output will not be consumed

Related