简体   繁体   English

如何从节点应用程序启动交互式bash脚本?

[英]How can I start an interactive bash script from a node app?

I'm building a command-line app in Node which is basically a setup wizard. 我正在Node中构建一个命令行应用程序,这基本上是一个安装向导。 At some point in the script, I'd like to start an openssl script which has its own stdout and prompts, and then ideally return to my Node app when it's done. 在脚本的某个时刻,我想启动一个具有自己的stdout和提示的openssl脚本,然后在完成后理想地返回到我的Node应用程序。

I've tried using spawn but am having trouble showing the stdout. 我试过使用spawn但是显示标准输出时遇到问题。 Is this practically possible? 这实际上可行吗?

Yes, this is possible, you can pipe standard input and output to your parent process like this, 是的,这是可能的,您可以像这样通过管道将标准输入和输出传输到父进程,

// Child will use parent's stdios
spawn('yourcommand', [], { stdio: 'inherit' });

first parameter is your command, second parameter is command parameters and third parameters is how to handle standard inputs and outputs, 第一个参数是您的命令,第二个参数是命令参数,第三个参数是如何处理标准输入和输出,

Refer this documentation for more information, https://nodejs.org/api/child_process.html#child_process_options_stdio 有关更多信息,请参阅此文档, https://nodejs.org/api/child_process.html#child_process_options_stdio

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

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