core module child_process.exec issue with <() command.
I executed same command in my bash and zsh shell everything works fine. Once I copy same command to code I get this error.
Shell command:
comm -13 <(sort new.csv | uniq) <(sort old.csv | uniq) > diff.csv
When executing same shell command it trows me error:
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `comm -13 <(sort new.csv | uniq) <(sort old.csv | uniq) > diff.csv'
Code:
exec(`comm -13 <(sort new.csv | uniq) <(sort old.csv | uniq) > diff.csv`,
(error, stdout, stderr) => {
if (error) {
return error
}
console.log(`${stdout}`)
console.log(`${stderr}`)
})
After troubleshooting I think problem is with <(
part of the command.
Try passing the shell
option to child_process.exec
, e.g. { "shell": "/bin/bash" }
, when you鈥檙e using shell-specific syntax like this
Works. Thank you very much.
Hey,
I am facing the same issue.
exec('jsdoc -X ./src/!(selector)/*.js > ./documentation/jsdocAST.json', { "shell": "/bin/bash" },(err, stdout, stderr) => {
if (err) {
//some err occurred
console.error(err)
} else {
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
}
});
isn't it correct?
Most helpful comment
Try passing the
shell
option tochild_process.exec
, e.g.{ "shell": "/bin/bash" }
, when you鈥檙e using shell-specific syntax like this