Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js - sending key-shortcuts to child process

My program spawns "ssh" as a child process, conntects to a server and is then able to write to the stream and read its output.

This all works fine. When I write "ls" to the process stream I get a list of the files.

But now, I want send key shortcuts to this process, so that I can abort the running process in the ssh session.

I know this can also be done through the stream, but where can I read about WHAT I must send to the process to make it understand my key shortcuts?

Thanks for any help!

like image 658
Van Coding Avatar asked Apr 13 '11 13:04

Van Coding


People also ask

What is child_process spawn?

child_process.exec() : spawns a shell and runs a command within that shell, passing the stdout and stderr to a callback function when complete.

What is Libuv and how does Node.js use it?

libuv: libuv is a C library originally written for Node. js to abstract non-blocking I/O operations. Event-driven asynchronous I/O model is integrated. It allows the CPU and other resources to be used simultaneously while still performing I/O operations, thereby resulting in efficient use of resources and network.


1 Answers

With a normal ssh session, sending '~' after a newline is the escape character to control the ssh program itself. For example '~.' will close the connection.

Search for 'tilde' on the manpage.

Update:

On re-reading your question, I think you are probably wanting to send Ctrl-* to the remote process running in the ssh session rather than talking to the ssh process itself. You might just be able to send the ASCII sequence that the Ctrl key would generate:

sshprocess.stdin.write("\x03")

ASCII character 0x03 is what Ctrl-C becomes. This is from the ancient days of dumb terminals. More about ASCII control sequences.

like image 62
kanaka Avatar answered Oct 17 '22 10:10

kanaka