I have been trying to call an custom bash script using child_process spawn module from my node application and I want to capture the stdout echoed by the shell script. I have tried listening to 'data' event but nothing helps. Here is the code:enter code here
const { spawn } = require('child_process');
const subprocess = spawn('.\\start_recording.sh', [], {shell:true});
subprocess.stdout.on('data', (data) => {
data = data.toString();
console.log(`Received chunk ${data}`);
});
I even tried using:
subprocess.stderr.pipe(process.stderr, {end: false});
subprocess.stdout.pipe(process.stdout, {end: false});
Still 'data' event not get listened.
Here is my bash script start_recording.sh:
#!/bin/bash
echo something