【问题标题】:ShelllJS exec returning null for every command -- Atom Package DevelopmentShelllJS exec 为每个命令返回 null —— Atom 包开发
【发布时间】:2016-09-13 23:40:25
【问题描述】:

我正在创建一个 Atom 包并尝试合并一个 ShellJS 命令。我想使用exec() 命令,每次命令都返回null。

shelljs = require 'shelljs/global'

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

为什么?

【问题讨论】:

  • 我试过console.log(exec('which git').code);,效果很好。 Shelljs 版本为 0.7.4。也许这个问题已经在 shelljs 中修复了。

标签: node.js atom-editor shelljs


【解决方案1】:

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

这会尝试运行名为which 的外部可执行文件,但没有这样的程序。 which是shell内置命令,不是独立程序,所以会失败。

console.log which 'git' // 返回正确的路径

这使用了 shelljs which 函数,它直接模拟了 shell 中的同一命令,所以它可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    相关资源
    最近更新 更多