Standard Method (no library)
You don't have to parse the command string into arguments, there's an option on child_process.spawn
named shell
.
options.shell
If true
, runs command inside of a shell.
Uses /bin/sh
on UNIX, and cmd.exe
on Windows.
Example:
let command = `some_script --option="Quoted Option" -d --another-option 'Quoted Argument'`
let process = child_process.spawn(command, [], { shell: true }) // use `shell` option
process.stdout.on('data', (data) => {
console.log(data)
})
process.stderr.on('data', (data) => {
console.log(data)
})
process.on('close', (code) => {
console.log(code)
})