是否有与 Python 的 subprocess.run 等效的 Node.js? [英] Is there a Node.js equivalent to Python's subprocess.run?

查看:71
本文介绍了是否有与 Python 的 subprocess.run 等效的 Node.js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望从 node.js 执行 shell 命令.我希望将标准输出显示到终端.在 python 中,我可以使用 subprocess.run 来做到这一点.在 node.js 中,我看到 child_process.exec,但这会返回一个 stdout 缓冲区,而不是自动显示到终端.

I am looking to execute shell command from node.js. I would like the stdout to be displayed to the terminal. In python I can do this with subprocess.run. In node.js I see child_process.exec, but this returns a buffer of stdout instead of automatically displaying to the terminal.

推荐答案

就我而言,我使用 child_process.execAsync 并将 stdio 选项设置为 使其工作>继承像这样:

In my case I got it working using child_process.execAsync with the stdio option set to inherit like this:

child_process.execAsync("git push --tags", { stdio: "inherit" })

我需要 git 来显示密码提示并允许用户进行输入.

I needed git to show the prompt for the passphrase and allow user to make the input.

这篇关于是否有与 Python 的 subprocess.run 等效的 Node.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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