如何在node.js的子生成过程中捕获PowerShell Write-Progress文本? [英] How to capture PowerShell Write-Progress text in child spawn process in node.js?

查看:53
本文介绍了如何在node.js的子生成过程中捕获PowerShell Write-Progress文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在node.js中,我创建了这样的子进程

In node.js I create child processes like this for example

child_process.spawn('powershell.exe', ['-executionpolicy', 'remotesigned', '-File', 'save_site_login_web.ps1', data.app_catalogue_url, data.ids.join(",")], { windowsHide:true });

const handler = (data) => {
     // send data to client
};
    
watcher_shell.stdout.on('data', handler);
watcher_shell.stderr.on('data', handler);

但是,在子进程中,它显示了如下图所示的进度条(我是通过Powershell终端手动运行它得到的).浅蓝色背景顶部的区域是静态的,并停留在顶部,而其中的文本会更新.

However, in the child process, it displays a progress bar like this picture (I got this from running it manually from a powershell terminal). The area on top with the light blue background is static and stays on top, while the text in it updates.

但是,此进度文本不会在stdout或stderr中捕获.如何在node.js中捕获此流?

However this progress text doesn't get captured in stdout or stderr. How can I capture this stream in node.js?

谢谢

推荐答案

mklement0所述,进度流不是可直接重定向.

As mklement0 stated, the progress stream is not directly redirectable.

也就是说,由于Windows 1809+,有了新的伪控制台(ConPTY)API,该API基本上允许任何程序像控制台一样工作,从而捕获直接写到控制台的输出.

That being said, since Windows 1809+ there is the new pseudo console (ConPTY) API, which basically allows any program to act like the console, thus capturing output that is written directly to the console.

进行快速搜索,有一个 node-pty 模块,据说该模块利用了ConPTYWindows上的API.我没有尝试过,但是看起来很有希望(VS Code正在将其用于集成终端).

Doing a quick search, there is the node-pty module which supposedly utilizes the ConPTY API on Windows. I haven't tried it but it looks promising (VS Code is using it for its integrated terminal).

这篇关于如何在node.js的子生成过程中捕获PowerShell Write-Progress文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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