node.js - why the nodejs spawn api dont call no event (onexit,onend,onerror) and sync dont wait command is completed? -


this function contains 2 bugs:

1) output not printed , no event executed. if pass option stdio=true output printed anyway no event (close,error,exit) executed

2) sync dont wait expected. if dont call onclose ... sync might wait indefinitelly ... istead process finished . didnt use spawnsync because output in case available when command completed. not solution when output long or interactive

var shellexecute = function (path, cmd) {      console.log('\t' + cmd)     function asyncfunction(callback) {         var proc = $.proc.spawn(cmd, {cwd: path, encoding: 'utf8'});         proc.stdin && proc.stdin.pipe(process.stdin);         proc.stdout && proc.stdout.pipe(process.stdout);         proc.stderr && proc.stderr.pipe(process.stderr);          proc.on('close', function (code) {             console.log('closing code: ' + code);             callback(null);          });          proc.on('exit', function (code) {             proc.stdin && proc.stdin.unpipe(process.stdin);             proc.stdout && proc.stdout.unpipe(process.stdout);             proc.stderr && proc.stderr.unpipe(process.stderr);             console.log('closing code: ' + code);             callback(null);          });          proc.on('error', function (error) {             console.log('error: ' + error);             callback(null);          });         //process.stdin.end();     }      $.sync(function () {         asyncfunction.sync();     });      return; } 


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -