我如何运行在节点子进程执行中具有自己的选项的命令

发布于 2025-02-02 05:30:34 字数 706 浏览 3 评论 0原文

我正在创建Make Node Cli自动化我的NPM软件包发布,我对这个问题感到震惊。确认后,我想运行命令语义释放,但问题它具有自己的提示 我当前使用exec命令,但它没有显示语义释放

代码创建的任何提示。

const timer = showLoading(`running ${chalk.blue(command)} `);
exec(command, (error, stdout, stderr) => {
                process.stdout.write(chalk.dim(`\r running ${chalk.blue(command)}   `));
                clearInterval(timer);
                defaults.onFinish();
                if (error) {
                    defaults.onError(error);
                    console.log(error);
                }
                defaults.onSuccess(stdout);
                console.log(stdout);
            });

I am creating make node CLI automate my npm package publishing, I am struck by this problem. After all Confirmation, I want to run the command semantic-release but problem it has its own prompts
I currently use exec command but It does not show any prompts created by semantic-release

Code

const timer = showLoading(`running ${chalk.blue(command)} `);
exec(command, (error, stdout, stderr) => {
                process.stdout.write(chalk.dim(`\r running ${chalk.blue(command)}   `));
                clearInterval(timer);
                defaults.onFinish();
                if (error) {
                    defaults.onError(error);
                    console.log(error);
                }
                defaults.onSuccess(stdout);
                console.log(stdout);
            });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生一梦 2025-02-09 05:30:34

您可以通过产生同步子过程来显示提示来自父过程的管道。

JS:

import { spawnSync } from 'child_process';
let { status } = spawnSync('./test.sh', [], { stdio: 'inherit' });
if (status > 0) { throw new Error('spawned process exited abnormally'); }

test.sh

#!/bin/bash
read -p 'enter something: ' value
[ -z "$value" ] && exit 1
echo "$value"

You can show the prompts by spawning a synchronous child process that inherits it's stdio pipes from the parent process.

JS :

import { spawnSync } from 'child_process';
let { status } = spawnSync('./test.sh', [], { stdio: 'inherit' });
if (status > 0) { throw new Error('spawned process exited abnormally'); }

test.sh

#!/bin/bash
read -p 'enter something: ' value
[ -z "$value" ] && exit 1
echo "$value"
丑疤怪 2025-02-09 05:30:34

我已经使用这种方式来创建自己的cli,这是创建我想要的所有命令并做我想做的所有命令的简单方法图像的很好解释

单击此处

I have used this way to create my own CLI, it's an easy way to create all the commands that I want and to do what I want, check the link maybe that helps you, in the website there also good explanation with images

Click here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文