I\'m trying to launch a shell command from Node.js, without redirecting that command\'s input and output -- just like shelling out to a command using a shell script, or
You can replace exec by spawn and use the shell syntax simply with:
exec
spawn
const {spawn} = require ('child_process'); const cmd = 'ls -l | grep test | wc -c'; const p = spawn (cmd, [], {shell: true}); p.stdout.on ('data', (data) => { console.log (data.toString ()); });
The magic is just {shell: true}.
{shell: true}