node.js - 有没有办法从节点中的 child_process.spawn 方法获得完整的输出
问题描述
我正在尝试ng lint --format json
使用节点的child_process
spawn 方法运行命令。代码如下所示:
const spawn = require('child_process').spawn;
const fs = require('fs-extra');
const jsonLog = fs.createWriteStream('test.json', { flags: 'a' });
const linter = spawn('ng', ['lint', '--format', 'json']);
linter.stdout.pipe(jsonLog);
如您所料,我正在尝试将 JSON 输出到文件中。我面临的问题是我没有得到完整的 JSON 输出。它在某些时候被截断,使其成为无效的 JSON。我认为它必须与缓冲区大小有关。
现在你们中的大多数人会建议我这样做:
ng lint --format json > jsonFile.json
我已经意识到了。我想以编程方式进行,因为我正在尝试为它构建一个实用程序。如果您有任何想法或解决方案,请告诉我。
解决方案
推荐阅读
- vue.js - 在 Vert.x (w/ES4X) 上运行 Vuetify
- javascript - Redmine Rest API:如何上传带有附件的 Wiki 页面
- image - 如何将屏幕上的图像添加到 PDF(使用 Itextsharp)
- jquery - 使用 render_to_string 库不起作用
- c++ - std::string 标头是否仅在 Visual Studio 中?
- sql - 当列在位置 2 中包含 1 时排除行而不使用函数
- python - 如何安装 practnlp 工具
- asp.net - Bootstrap 复选框在回发后失去选中状态。我怎样才能阻止这个?
- http - 微服务上下文中的 WireMock 记录 - 一个客户端调用多个服务器
- android - 从后台返回时,Android 片段被置于前一个片段之上