A
A
arseniylebedev2019-01-04 22:16:22
JavaScript
arseniylebedev, 2019-01-04 22:16:22

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"

JS
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

1 answer(s)
A
arseniylebedev, 2019-01-05
@arseniylebedev

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 question

Ask a Question

731 491 924 answers to any question