Node: child_process exec '<()' unexpected token

Created on 7 Mar 2017  路  3Comments  路  Source: nodejs/node

  • Version: v7.7.1
  • Platform: Linux ai 4.9.11-1-ARCH x86_64 GNU/Linux
  • Subsystem: child_process

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.

child_process question

Most helpful comment

Try passing the shell option to child_process.exec, e.g. { "shell": "/bin/bash" }, when you鈥檙e using shell-specific syntax like this

All 3 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cong88 picture cong88  路  3Comments

jmichae3 picture jmichae3  路  3Comments

dfahlander picture dfahlander  路  3Comments

stevenvachon picture stevenvachon  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments