DEV Community

DOEHOONLEE
DOEHOONLEE

Posted on

nodejs exec(``) runs commands in different shell

What is your question/issue (provide as much detail as possible)?

  • For example, when running exec(echo $SHELL), I get 'bin/zsh' which is what I am also using on my terminal. However, when running different commands like exec(echo $SHELL), I keep getting an error saying that "Error: Command failed: tree /bin/sh: tree: command not found"

What technologies are you using?

  • Running shell commands with nodejs v12 exec() on WebStorm

What were you expecting to happen?

  • I would like to run shell commands using exec()

What is actually happening?

  • error says "Error: Command failed: tree /bin/sh: tree: command not found" as if I am trying to run the command in /bin/sh

What have you already tried/thought about?

  • I ran exec(``, {shell: '/bin/zsh'}, () => {}), but it keeps saying that the command is not found

What errors are you getting?

  • error says "Error: Command failed: tree /bin/sh: tree: command not found" as if I am trying to run the command in /bin/sh

Top comments (1)

Collapse
 
ncpa0cpl profile image
ncpa0cpl

Aren't you focusing on the wrong thing? It shouldn't really matter what shell you use, bash or zsh, should make almost no difference. From what you are saying it would seem that the problem is the tree command, are you sure you have it installed and it's present in the PATH?