我试图使用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)我只想知道是否有任何工作或解决方案来执行代码。我们很感激你的帮助。
谢谢。
发布于 2015-11-11 12:49:57
使用test.sh的完整路径:
var shell = require("shelljs");
var output = shell.exec("bash /path/to/test.sh",{silent:true,async:false}).output;
console.log(output);看起来像shelljs搜索文件: /tmp/shelljs_b656f0ddaa7c3b096e97,您把test.sh放在哪里?在nwjs附近?你是怎么运行代码的?从devtools来的?从项目中?从拥挤的项目?
还有,你为什么需要贝壳?Nwjs已经有了可以使用shell的internall:
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://stackoverflow.com/questions/33458437
复制相似问题