Sunday, 15 April 2012

node.js - execute a shell script inside nodejs code -



node.js - execute a shell script inside nodejs code -

i want execute next command within node js code

diff <(git log 01) <(git log 02)

in command line working , gettig desired output want

here node code

var command = "diff <(git log 01) <(git log 02)" console.log(command) exec(command, function (error, stdout, stderr) { if (error !== null) { console.log(error) } else { console.log(stdout) } } });

but while executing above code getting'

diff <(git 01) <(git log 02) { [error: command failed: /bin/sh: 1: syntax error: "(" unexpected ] killed: false, code: 2, signal: null }

try running this:

var spawn = require('child_process').spawn; var command = "diff <(git log 01) <(git log 02)"; console.log(command) var diff = spawn('bash', ['-c', command]); diff.stdout.on('data', function (data) { console.log('stdout: ' + data); }); diff.stderr.on('data', function (data) { console.error('stderr: ' + data); });

node.js

No comments:

Post a Comment