I wanted to use cspell --file-list command as a child process in Node Js. I wanted to pass large array of strings to this child process and feed it by stdin.
var child = spawn('cspell --file-list',[], {shell:true});
Now I wanted to pass strings one by one to this child process.
Can someone help me in this with small example.
send files as an argument:
const spawn = require('child_process').spawn;
const cmd = 'cspell';
const checkFiles = (files) => {
const proc = spawn(cmd, ['--file-list'].concat(files), {shell: true });
const buffers = [];
proc.stdout.on('data', (chunk) => buffers.push(chunk));
proc.stderr.on('data', (data) => {
console.error(`stderr: ${data.toString()}`);
});
proc.stdout.on('end', () => {
const result = (Buffer.concat(buffers)).toString();
console.log(`done, result:\n${result}`);
});
};
// pass files array
checkFiles(['some-file', 'another-file']);