简体   繁体   中英

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. 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.

I've tried using spawn but am having trouble showing the stdout. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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