node.js-向子进程发送快捷键 [英] node.js - sending key-shortcuts to child process

查看:134
本文介绍了node.js-向子进程发送快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序将"ssh"作为子进程生成,连接到服务器,然后能够写入流并读取其输出.

一切正常.当我在流程流中写入"ls"时,我会得到文件列表.

但是现在,我想向该过程发送快捷键,以便我可以在ssh会话中终止正在运行的过程.

我知道这也可以通过流完成,但是我在哪里可以了解到我必须发送给流程的内容,以使其了解我的关键快捷方式?

感谢您的帮助!

解决方案

对于普通的ssh会话,在换行符之后发送〜"是转义字符,用于控制ssh程序本身.例如〜".将关闭连接.

联机帮助页上搜索波浪号". /p>

更新:

在重新阅读您的问题时,我认为您可能希望将Ctrl- *发送到ssh会话中运行的远程进程,而不是与ssh进程本身进行对话.您可能只能够发送Ctrl键将生成的ASCII序列:

sshprocess.stdin.write("\x03")

Ctrl-C变成

ASCII字符0x03.这是从古时代的哑终端开始的.有关 ASCII控制序列的更多信息.

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!

解决方案

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.

这篇关于node.js-向子进程发送快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆