gpt4 book ai didi

node.js - 如何抑制shelljs中的错误?

转载 作者:搜寻专家 更新时间:2023-10-31 22:42:59 25 4
gpt4 key购买 nike

当我在 Node 中运行以下代码时:

var shell = require('shelljs');
var files = shell.ls('-R', './**/foobar');
console.log('Files found:\n' + files.join('\n'));

我在输出中看到了这个:

ls: no such file or directory: ./**/foobar

如何抑制 stderr,使其不被显示?

最佳答案

我花了一点时间才弄明白,但是你需要将 shelljs 配置为静音,如下所示:

var shell = require('shelljs');
shell.config.silent = true;

来自README ,这个:

Suppresses all command output if true, except for echo() calls. Default is false.

关于node.js - 如何抑制shelljs中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40159919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com