At the moment I'm using the "gulp-run" plugin to run a .bat file. That plugin has now been deprecated and I'm looking for the best way to execute the .bat now.
Current code:
var gulp = require('gulp');
var run = require('gulp-run');
module.exports = function() {
run('c:/xxx/xxx/runme.bat').exec();
};
Solution as per @cmrn suggestion:
var exec = require('child_process').exec;
var batchLocation = 'c:/xxx/xxx/runme.bat';
gulp.task('task', function (cb) {
exec(batchLocation, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
})
pipe() method attaches a Writable stream to the readable, causing it to switch automatically into flowing mode and push all of its data to the attached Writable.
If you just want a task that runs some function, then just do that: gulp. task('my-custom-task', function () { myCustomFunction('foo', 'bar'); });
The gulp tasks are writted in javascript file called gulpfile. js which will be executed by Gulp tool. Gulp can be installed by using npm (Node Package Manager) tool either machine wide or locally to the application.
If you need to run the script as part of a gulp stream (i.e. in pipe()
) you can use gulp-exec. If not, you can just use child_process.exec
as described in the gulp-exec README, copied below.
var exec = require('child_process').exec;
gulp.task('task', function (cb) {
exec('ping localhost', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With