Answer the question
In order to leave comments, you need to log in
Error running dir command via child_process.spawn?
The code should call the dir command via spawn. I'm running on Windows 7.
There is such an error "Error: spawn dir ENOENT"
const child_process = require('child_process');
const dir = child_process.spawn('dir');
dir.stdout.on('data', (data) => {
console.log(data);
});
dir.stderr.on('data', (data) => {
console.log(data);
});
dir.on('close', (code) => {
console.log(code);
});
dir.on('error', (err) => {
console.log(`Error: ${err}`);
});
Answer the question
In order to leave comments, you need to log in
const child_process = require('child_process');
const ch = child_process.spawn('test.bat', [], {
shell: true,
})
ch.stdout.on('data', (data) => {
console.log(`Stdout: ${data}`);
});
ch.stderr.on('data', (data) => {
//console.log(`Stderr: ${data}`);
});
ch.on('close', (code) => {
//console.log(`Code: ${code}`);
});
ch.on('error', (err) => {
//console.log(`Error: ${err}`);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question