从Node.JS运行二进制文件并准确地在控制台上中继行为,包括提示 [英] Run a binary from Node.JS and relay the behavior exactly on the console, including prompts

查看:68
本文介绍了从Node.JS运行二进制文件并准确地在控制台上中继行为,包括提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node.JS创建一个cli工具。我从节点内部运行另一个二进制文件,然后另一个进程在某个时候要求输入密码。

I'm making a cli tool with Node.JS. I run another binary file from within node, and the other process asks for a password at some point.

所以我需要的是简单地启动另一个进程,然后输入它由终端负责,因此其他进程将处理提示和控制台输出。

So what I need is to simply launch the other process, and put it "in charge" of the terminal, so the other process handles the prompts and the console output.

推荐答案

您可以使用继承 用于 stdio选项 spawn

const spawn = require( 'child_process' ).spawn;
spawn( '/path/to/binary', [], { stdio: 'inherit' } );

这篇关于从Node.JS运行二进制文件并准确地在控制台上中继行为,包括提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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