I do understand the difference of concept between .exec and .spawn.
I am trying to run a simple command, lets say echo.
With .exec, the command does work as expected.
With .spawn I receive Error: spawn echo ENOENT.
What am I doing incorrectly?
// WORKS AS EXEPCTED
const exec= require('child_process').exec;
exec("echo hello", function(err, stdout) {
console.log(stdout);
});
// THROWS
const spawn = require('child_process').spawn;
spawn("echo", ["hello"]); // fail
Error received :
Error: spawn echo ENOENT
at exports._errnoException (util.js:1026:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
I am running on Windows!
Thanks for your help and patience.
I finally find the answer to my question.
The problem is that the spawn implementation on Windows can only start executables.
To avoid this problem, you can use win-spawn.
Related
index.js file
R("message.R")
.data("hello world", 20)
.call(function(err, d) {
if (err) console.log('err:', err);
console.log('hiiii:', d);
});
message.R file
Print('ankit is here')
In command line, when running node index.js, getting error spawn Rscript ENOENT
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn Rscript ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3) Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
If you are also facing the same issues, after spending 4-5 hour time, I get to know that we need to install R in your local machine. the procedure of installing R is as mentioned in the link.install R in ubuntu
After that type R,
you will get R environment
Install
install.packages("dplyr");
Need to run a separate power shell script using nodejs in my Ubuntu OS
var spawn = require("child_process").spawn,child;
child = spawn("powershell.exe",["file path"]);
Error: spawn powershell.exe ENOENT
at Process.ChildProcess._handle.onexit
(internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain
(internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit
(internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
[... lines matching original stack trace ...]
I'm trying to convert a markdown to pdf using the npm package markdown-pdf with the code below of index.js and I'm getting these errors after run node index.js.
The first error I got is on my Windows 10 Host Machine, and the second one is on my Ubuntu Guest VirtualBox VM.
Any idea of how to solve this? Anything related with phantomjs package?
index.js
var markdownpdf = require("markdown-pdf"),
fs = require("fs")
markdownpdf().from("./README.md").to("./curriculo.pdf", function() {
console.log("Converted to PDF successfully!")
})
Terminal Output Error - Windows Host VM
internal/child_process.js:319
throw errnoException(err, 'spawn');
^
Error: spawn EPERM
at exports._errnoException (util.js:1018:11)
at ChildProcess.spawn (internal/child_process.js:319:11)
at exports.spawn (child_process.js:378:9)
at Object.exports.execFile (child_process.js:143:15)
at WriteStream.<anonymous>
(C:\Users\User\Documents\localdev\curriculo\node_modules\markdown-pdf\index.js:117:22)
at emitNone (events.js:91:20)
at WriteStream.emit (events.js:185:7)
at finishMaybe (_stream_writable.js:512:14)
at afterWrite (_stream_writable.js:386:3)
at onwrite (_stream_writable.js:376:7)
Terminal Output Error - Ubuntu Guest VM
stream.js:74
throw er; // Unhandled stream error in penter code hereipe.
^
Error: spawn /media/sf_localdev/curriculo/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe ENOENT
at exports._errnoException (util.js:870:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)
With the help gulp yeoman-webapp 'im wolf. But it also serves on the command line, I get the following error gulp. Can you help me? Thank you in advance.
I work in Windows 10 and 64 bit computing.
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
Try to put in your system variables in the PATH :
C:\Windows\System32;
I have script called sassy.js
var spawn = require('child_process').spawn,
rubySass = spawn('sass', ['--watch scss:.tmp/css', '--sourcemap=auto', '--style=expanded', '--unix-newlines']);
which I try to run with node sassy.js
$ node sassy.js
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn sass ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
It's strange because this code works:
var exec = require('child_process').exec,
rubySass = exec('sass --watch scss:.tmp/css --sourcemap=auto --style=expanded --unix-newlines');
I choose spawn beacuse finally I want to return stdout which I could redirect to node package called clean-css by Npm run script
"scripts": {
"build-sass:clean": "node sassy.js |
}
with: npm run build-sass:clean
EDITED
After help from Lovell Fuller I updated sassy.js rubySass = spawn('c:/Ruby21-x64/bin/sass', ['--watch scss:.tmp/css', '--sourcemap=auto', '--style=expanded', '--unix-newlines'])
but node sassy.js stills yelds
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn c:/Ruby21-x64/bin/sass ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
I've tried with c:/Ruby21-x64/bin/sass.batbut despite no errors, there is no output as well :-/
exec uses the shell to run commands and is able to locate and prefix sass with its full path.
spawn does not run commands via the shell so you'll need to provide the full path, e.g. /usr/bin/sass.
If you're unsure what the full path needs to be, the which sass command should provide this.
I don't know if this will be relevant but did you forget a end quotation?
"scripts": {
"build-sass:clean": (--->)"node sassy.js |
}
"scripts": {
"build-sass:clean": "node sassy.js" |
}