node.js - Why is execSync not working in my code? -


i'm trying out various child process methods in nodejs. execute linux command, tried code, prints current working directory:

var execsync = require('child_process').execsync;  function commandoutput(error, stdout, stderr) {     if (stderr !== null) {         console.error(stderr);     }     if (error !== null) {         console.error('execution error: ' + error);     }     if (stdout)console.log(stdout);      console.log("done"); }  var commandtoexecute = "pwd"; execsync(commandtoexecute, commandoutput);  console.log("executed"); 

while works fine if replace execsync exec, above code, i.e, execsync gives following error:

 execsync(commandtoexecute, commandoutput); ^ typeerror: undefined not function     @ object. (/home/user_name/fil.js:24:1)     @ module._compile (module.js:456:26)     @ object.module._extensions..js (module.js:474:10)     @ module.load (module.js:356:32)     @ function.module._load (module.js:312:12)     @ function.module.runmain (module.js:497:10)     @ startup (node.js:119:16)     @ node.js:902:3 

why happening? should change work?

try updating node latest stable version 6.10)

you can running:

curl -sl https://deb.nodesource.com/setup_7.x | sudo -e bash -  sudo apt-get install -y nodejs 

you can check version running

nodejs -v 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -