简体   繁体   English

进程在节点REPL上运行

[英]Process running on top of node REPL

I would like to run a process on top of node REPL. 我想在节点REPL上运行一个进程。 The objective here is to allow users to use the node REPL the way they would by simply typing a command into their terminals, but to load some modules automatically into that REPL. 此处的目的是允许用户通过简单地在终端中键入命令来使用节点REPL,而将某些模块自动加载到该REPL中。

The solution to this problem would be best if somehow the stdin was piped back and forth to the REPL running in the background, but also satisfactory if the REPL simply had some modules loaded into it prior to allowing the user to inout stdin. 如果以某种方式将stdin来回传递到后台运行的REPL,则解决此问题的方法将是最好的,如果REPL在允许用户输入stdin之前只是简单地将一些模块加载到其中,则也可以令人满意。

What I could do would be to work with process.stdin.resume() to allow users to input commands, evaluate them, and process them inside of the already running node process, but this is duplicating functionality of the already existing node REPL. 我可以做的是使用process.stdin.resume()来允许用户输入命令,评估它们并在已经运行的节点进程中处理它们,但这是在复制已经存在的节点REPL的功能。

Is there any way to do this? 有什么办法吗? Does child_process have a medium for this kind of control? child_process是否具有用于这种控制的媒介?

Any proposed solution can also use es6. 任何建议的解决方案也可以使用es6。 Thanks in advance. 提前致谢。

EDIT: Please let me know what I can do to improve this question as it has been viewed several times, but not touched. 编辑:请让我知道我可以做些什么来改善这个问题,因为它已经被浏览了好几次,但是没有被触及。 I cannot provide an example because I do not know how I would go about doing something like this. 我无法提供一个示例,因为我不知道该怎么做。

Have you seen the built in repl module? 您看过内置的repl模块吗?

https://nodejs.org/api/repl.html https://nodejs.org/api/repl.html

It looks like it covers everything you want to do. 看起来它涵盖了您想要做的所有事情。

If you want a custom context, you would probably need to pass a custom eval function. 如果需要自定义上下文,则可能需要传递自定义eval函数。 The node documentation has examples. 节点文档包含示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM