如何抑制Shell.js中的错误?

Dou*_*low 5 node.js shelljs

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

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

我在输出中看到了这一点:

ls: no such file or directory: ./**/foobar
Run Code Online (Sandbox Code Playgroud)

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

Dou*_*low 5

我花了点时间弄清楚了,但是您需要将shelljs配置为保持沉默,如下所示:

var shell = require('shelljs');
shell.config.silent = true;
Run Code Online (Sandbox Code Playgroud)

README中,这是:

如果是true,则禁止所有命令输出(echo()调用除外)。默认值为false