I would like to git pull, mit and push from nodeJS with child_process - is this suppose to work?
var cmd = require('child_process');
var mmandString = "cd c:\\xampp\\htdocs\\MenuMakerServer\\experiments\\editormenu && git mit -am 'menu.json changes' && git push origin main";
cmd.exec(mmandString , function (error: any, stdout, stderr) {
if (error) {
callback(error.stack, null);
}
});
EDIT:
OK, I managed to get this to work:
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
var options = {cwd:"c:\\xampp\\htdocs\\MenuMakerServer\\projects\\editormenu"};
exec("git status && git pull && git mit -am 'menu changed' && git push", options, puts);
I would like to git pull, mit and push from nodeJS with child_process - is this suppose to work?
var cmd = require('child_process');
var mmandString = "cd c:\\xampp\\htdocs\\MenuMakerServer\\experiments\\editormenu && git mit -am 'menu.json changes' && git push origin main";
cmd.exec(mmandString , function (error: any, stdout, stderr) {
if (error) {
callback(error.stack, null);
}
});
EDIT:
OK, I managed to get this to work:
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
var options = {cwd:"c:\\xampp\\htdocs\\MenuMakerServer\\projects\\editormenu"};
exec("git status && git pull && git mit -am 'menu changed' && git push", options, puts);
Share
Improve this question
edited Aug 6, 2013 at 18:05
Guy
asked Aug 6, 2013 at 17:44
GuyGuy
13.4k17 gold badges89 silver badges129 bronze badges
5
-
No that won't work... it looks like you are bining both DOS shell mands and Unix shell mands. Specifically
c:\
is DOS and using&&
to chain mands is Unix shell. Which environment are you using? – Hogan Commented Aug 6, 2013 at 18:03 - mmm... i guess that using cygwin (new to it) made me confused.. – Guy Commented Aug 6, 2013 at 18:04
- works now - should i delete the questions? (tnx.btw) – Guy Commented Aug 6, 2013 at 18:06
-
1
You should post your (correct)
cwd
solution as an answer and accept it. :) – Ry- ♦ Commented Aug 6, 2013 at 18:09 - Guy - I agree with @minitech – Hogan Commented Aug 6, 2013 at 19:17
2 Answers
Reset to default 4Define a node.js module something like below code.
exports.series = function(cmds, callback){
var execNext = function(){
exports.exec(cmds.shift(), function(error){
if (error) {
callback(error);
} else {
if (cmds.length) execNext();
else callback(null);
}
});
};
execNext();
};
Then you can run it:
myProcessor.series([
'cd c:\\xampp\\htdocs\\MenuMakerServer\\experiments\\editormenu'
'git mit -am "menu.json changes"',
'git push origin main '
], function(err){
console.log('executed many mands in a row');
});
NOTE: Here myProcessor is the require variable name (somethig like var myProcessor = require('./path/to/above/code/file');
) for the above code snippet.
No that won't work... it looks like you are bining both DOS shell mands and Unix shell mands. Specifically c:\
is DOS and using && to chain mands is Unix shell. Which environment are you using?
If you are using DOS
then you need make a .bat
and call the batch. This is nice becasuse you can use parameters.