A
A
Andrey Rogov2015-10-24 02:39:04
JavaScript
Andrey Rogov, 2015-10-24 02:39:04

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 процесса
]));

How can I get the id of a running process using gulp-shell or a similar tool?
Of course, you can get around the problem in every possible way, but the question is about getting the id of the running process in gulp.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aves, 2015-10-24
@rogallic

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);
});

M
Mark Doe, 2015-10-24
@mourr

Have a look at gulp-run , it makes it easy to capture and write stdout, I think this will solve your problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question