Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress errors in shelljs?

When I run the following code in node:

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

I see this in the output:

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

How can I suppress the stderr, keep it from being shown?

like image 958
Douglas Ludlow Avatar asked Oct 20 '16 16:10

Douglas Ludlow


1 Answers

Took me a bit to figure this out, but you need to configure shelljs to be silent, like so:

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

From the README, this:

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

like image 65
Douglas Ludlow Avatar answered Nov 15 '22 03:11

Douglas Ludlow