Answer the question
In order to leave comments, you need to log in
How to start a process in Gulp.js with a shell command, and then kill it?
I would like to run a test local server for testing ReST requests.
// Запустить можно командой:
gulp.task('startTestServ', ['beforeTask'], shell.task([
'./myTestServ &', // команда выведет в консоль id процесса
]));
// После этого запускаем, собственно, тесты:
gulp.task('restTests', ['startTestServ'], function() {
return gulp.src(['restTests/*.js'], {read: false})
.pipe(mocha());
});
// В конце убиваем тестовый сервер
gulp.task('killTestServ', shell.task([
'kill ???', // Но не знаем id процесса
]));
Answer the question
In order to leave comments, you need to log in
The standard child_process.spawn is enough:
var gulp = require('gulp');
var spawn = require('child_process').spawn;
var ping;
gulp.task('ping', function() {
ping = spawn('ping', ['localhost'], {
stdio: 'inherit' // для примера, серверу не нужно
});
});
gulp.task('test', ['ping'], function() {
setTimeout(function() {
ping.kill();
}, 2000);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question