Explosion Pills
Explosion Pills

Reputation: 191729

Allocate terminal with child_process

I'm using child_process to run a script that ultimately calls

ssh -t server "sudo command"

I get back:

Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo

Is there any way to make the process' stdin a terminal? It's being run like so;

var proc = child_process.spawn(pathToCommand, ["args"]);
proc.stdout.on("data", function (data) {                          
    socket.emit("running", "" + data);                                      
});                                                                         

proc.stderr.on("data", function (err) {                           
    socket.emit("error", "" + err);                                         
});                                                                         

proc.on("close", function (code) {                                
    socket.emit("finished", "" + code);                                     
});

I would like to avoid forcing terminal allocation for ssh via -tt. Instead I would just like to allocate a terminal for the process. Is this doable?

Upvotes: 0

Views: 292

Answers (1)

mscdex
mscdex

Reputation: 106696

The ssh2 module allows setting of a pty used by the remote end when using shell() or exec().

Upvotes: 0

Related Questions