Wildcards in child_process spawn()?

Viewed 3269

I want to execute a command like "doSomething ./myfiles/*.csv" with spawn in node.js. I want to use spawn instead of exec, because it is some kind of watch process and I need the stdout output.

I tried this

var spawn = require('child_process').spawn; 
spawn("doSomething", ["./myfiles/*.csv"]);

But then the wildcard *.csv will not interpreted.

Is it not possible to use wildcards when using spawn()? Are there other possibilities to solve this problem?

Thanks

Torben

3 Answers

Here's the simplest solution:

spawn("doSomething", ["./myfiles/*.csv"], { shell: true });

As @JamieBirch suggested in his comment, the key is telling spawn() to use the shell ({ shell: true }, see the docs), so the wildcard is properly resolved.

Related