在nwjs中使用shelljs执行命令?

我试图在nwjs中使用shelljs执行一个简单的命令,如下所示:

main.js:

var shell = require("shelljs"); var output = shell.exec("bash ./test.sh",{silent:true,async:false}).output; console.log(output); 

test.sh:

 echo "Hey there" 

当我在像这样的nodejs中运行上面的文件

 node main.js 

它工作没有任何问题。 但是当我尝试运行上面的代码使用nwjs(假设我们有index.html和main.js的基本项目结构设置),它给了我一个错误。

 [23874:1031/211359:INFO:CONSOLE(191)] ""shell.js: internal error"", source: node_modules/shelljs/src/common.js (191) [23874:1031/211359:INFO:CONSOLE(192)] ""Error: ENOENT: no such file or directory, open '/tmp/shelljs_b656f0ddaa7c3b096e97'\n at Error (native)\n at Object.fs.openSync (fs.js:540:18)\n at Object.fs.readFileSync (fs.js:392:15)\n at execSync (node_modules/shelljs/src/exec.js:109:24)\n at Object._exec (node_modules/shelljs/src/exec.js:214:12)\n at Object.exec (node_modules/shelljs/src/common.js:182:23)\n at file://main.js:33:16"", source: node_modules/shelljs/src/common.js (192) 

我只想知道是否有任何解决方法或解决scheme来执行代码。 帮助表示赞赏。

谢谢。

使用完整pathtest.sh:

 var shell = require("shelljs"); var output = shell.exec("bash /path/to/test.sh",{silent:true,async:false}).output; console.log(output); 

看起来像shelljssearch文件:/ tmp / shelljs_b656f0ddaa7c3b096e97你放置test.sh的地方? 在nwjs附近? 你如何运行代码? 从devtools? 从项目? 从打包的项目?

另外,为什么你需要shelljs? Nwjs已经有了可以与shell协同工作的API:

 var nwGui = require('nw.gui') , nwShell = nwGui.Shell , child_process = require('child_process') , exec = child_process.exec , execSync = child_process.execSync , execFile = child_process.execFile , execFileSync = child_process.execFileSync ; var output = execSync("bash /path/to/test.sh"); console.log(output); 

https://github.com/nwjs/nw.js/wiki/shell