0

I am creating an Atom package and trying to incorporate a ShellJS command. I want to use the exec() commmand, and it's returning null everytime, for every command.

shelljs = require 'shelljs/global'

console.log exec('which git').code // returns null
console.log which 'git' // returns the correct path

why?

Aymon Fournier
  • 4,323
  • 12
  • 42
  • 59
  • I tried `console.log(exec('which git').code);` and it works well. Shelljs version is 0.7.4. Maybe this issue has been fixed in shelljs. – shaochuancs Oct 25 '16 at 03:17

1 Answers1

0

console.log exec('which git').code // returns null

This tries to run an external executable named which but there's no such program. which is a shell built-in command, not a standalone program, so it fails.

console.log which 'git' // returns the correct path

This uses the shelljs which function, which is a direct analog to the same command in a shell, so it works.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274