I'm trying to execute a simple mand using shelljs in nwjs like this :
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"
When I run the above file in nodejs like this
node main.js
It works without any problems. But when I try to run the above code using nwjs(assuming we have the basic project structure setup with the index.html and main.js), it gives me an error.
[23874:1031/211359:INFO:CONSOLE(191)] ""shell.js: internal error"", source: node_modules/shelljs/src/mon.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/mon.js:182:23)\n at file://main.js:33:16"", source: node_modules/shelljs/src/mon.js (192)
I just want to know if there is any work around or solution to execute the code. Help is appreciated.
Thank you.
I'm trying to execute a simple mand using shelljs in nwjs like this :
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"
When I run the above file in nodejs like this
node main.js
It works without any problems. But when I try to run the above code using nwjs(assuming we have the basic project structure setup with the index.html and main.js), it gives me an error.
[23874:1031/211359:INFO:CONSOLE(191)] ""shell.js: internal error"", source: node_modules/shelljs/src/mon.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/mon.js:182:23)\n at file://main.js:33:16"", source: node_modules/shelljs/src/mon.js (192)
I just want to know if there is any work around or solution to execute the code. Help is appreciated.
Thank you.
Share asked Nov 1, 2015 at 1:45 dvenkatsagardvenkatsagar 9367 silver badges22 bronze badges 2- it seems like shelljs cant find a file, can you please try and run a global mand like ls? to see if the problem occurs then? – Alex Michailidis Commented Nov 1, 2015 at 9:54
- @alex rokabilis , I did try the global option, and that also was giving an error, I even tried it in electron context instead of nwjs but that also did not work. The weird thing is that the child_process.execSync works but this doesn't. – dvenkatsagar Commented Nov 8, 2015 at 15:01
1 Answer
Reset to default 5Use full path to test.sh:
var shell = require("shelljs");
var output = shell.exec("bash /path/to/test.sh",{silent:true,async:false}).output;
console.log(output);
Looks like shelljs searching file in: /tmp/shelljs_b656f0ddaa7c3b096e97 Where you place test.sh? Near nwjs? How you run code? From devtools? From project? From packed project?
Also, why you need shelljs? Nwjs already have internall API to work with shell:
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./nwjs/nw.js/wiki/shell