sanketbajoria / ssh2-promise

ssh with promise/async await and typescript support
https://www.npmjs.com/package/ssh2-promise
MIT License
148 stars 24 forks source link

How to stop a command? #3

Closed fgheorghe closed 6 years ago

fgheorghe commented 6 years ago

How do i stop a command, i.e.: tail: //use spawn, if you want to stream on output of command (async function(){ var socket = await ssh.spawn("tail -f /var/log.txt"); socket.on('data', () => { //file content will be available here }) })();

Basically, I would like to kill the tail command when terminating a connection.

Thank you

nallown commented 6 years ago

send a CTRL+C instruction to the socket. I'm not sure how to do that but you can just send a CTRL+C instruction to end it.

Also you can just close the socket connection. Maybe there's a socket.close() command.

fgheorghe commented 6 years ago

Thank you for your reply - sometimes when i close the socket, the command won't stop. Will try sending a CTRL+C instruction instead.

nallown commented 6 years ago

People are saying that \x003 or \x03 is a CTRL+C instruction btw.

sanketbajoria commented 6 years ago

Please pass {pty: true} as second parameter when spawning a tail command. Before closing, pass SIGKILL command via socket.

fgheorghe commented 6 years ago

Thank you all.

The following appears to have worked: Setting the pty to true, as per @sanketbajoria suggestion. Sending a \x03 before closing the connection.

Great community! Will close this "issue" now.