Sunday 6 December 2020

How to prefix every line of the output of a child_process spawn() call with text?

I execute several processes using spawn() from child_process.

const { spawn } = require('child_process');

spawn("sh", ["script1.sh"], { shell: false, stdio: "inherit"});
spawn("sh", ["script2.sh"], { shell: false, stdio: "inherit"});
spawn("sh", ["script3.sh"], { shell: false, stdio: "inherit"});

Question: How to prefix the output of the scripts with text?

The idea is that I would be able to easily distinguish what each script logs.

I went through the spawn documentation but couldn't find anything that would help achieve this.

Note: I cannot modify the scripts.



from How to prefix every line of the output of a child_process spawn() call with text?

No comments:

Post a Comment