Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 自定义节点JS REPL输入/输出流_Node.js_Visual Studio Code_Node Modules_Read Eval Print Loop_Node Repl - Fatal编程技术网

Node.js 自定义节点JS REPL输入/输出流

Node.js 自定义节点JS REPL输入/输出流,node.js,visual-studio-code,node-modules,read-eval-print-loop,node-repl,Node.js,Visual Studio Code,Node Modules,Read Eval Print Loop,Node Repl,我需要自定义REPL输入/输出流。例如,当某个事件发生时,我需要将一段脚本传递给REPL,然后获取它的输出并对其进行处理 为了更清楚地描述它,我正在开发一个提供REPL的。在我的例子中,我有一个vscode-WebView,从那里,我获得用户输入,然后我想将该输入传递给节点REPL,获得其输出并将其显示给用户 那么,我将如何实现这一目标?如果你需要更多的信息,请告诉我。提前谢谢 编辑1: const replServer = repl.start({ input: /* what sh

我需要自定义REPL输入/输出流。例如,当某个事件发生时,我需要将一段脚本传递给REPL,然后获取它的输出并对其进行处理


为了更清楚地描述它,我正在开发一个提供REPL的。在我的例子中,我有一个
vscode-WebView
,从那里,我获得用户输入,然后我想将该输入传递给节点REPL,获得其输出并将其显示给用户

那么,我将如何实现这一目标?如果你需要更多的信息,请告诉我。提前谢谢

编辑1:

const replServer = repl.start({
    input: /* what should be here? */,
    output: /* what should be here? */
});
编辑2: 有人能解释一下在上面的例子中,
输入
/
输出
参数的用法吗

  • 要创建repl服务器,只需执行以下操作
  • prompt是一个字符串,它是提示,stream是输入<代码>输入流需要是可读流,
    输出流
    需要是可写流。您可以阅读更多关于流的信息。一旦这些数据流开始工作,你就可以

    output_stream.on('data', (chunk) => {                                                                                                                                                            
       14   //whatever you do with the data                                                                                                                                                                     
       15 });                
    

    六羟甲基三聚氰胺六甲醚。。。一切看起来都很好,但只是一个小问题:在文档中我看到了
    getWritableStream()。我应该如何创建流?无法从某个地方获取。然后,如何将字符串传递到可读流
    。我的意思是:
    readableStream.read(“helloworld”)
    。然后这应该由
    repl
    来解释。我链接了节点文档,您应该能够获得所需的其他文档,并创建一个可写流do
    const writable=new stream.writable()
    
    output_stream.on('data', (chunk) => {                                                                                                                                                            
       14   //whatever you do with the data                                                                                                                                                                     
       15 });