9

I'm trying to execute something using gulp-shell. My gulfile.js contains the following content:

var gulp  = require('gulp'),
    shell = require('gulp-shell');

gulp.task('test', function() {
  shell(['echo test']);
});

Then I run it calling gulp test. This is the output I get:

Using gulpfile ~/gulpfile.js
Starting 'test'...
Finished 'test' after 2.62 ms

There's no output for my echo call.

I'm using an Ubuntu 14 VM that I connected to, using Putty.

Anyone got an idea what's wrong?

Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
NewGulpUserxx
  • 225
  • 4
  • 7

2 Answers2

18

That's because it's not the good way to use gulp-shell.

Try this, as seen in the gulp-shell README.

var gulp  = require('gulp'),
    shell = require('gulp-shell');

gulp.task('test', shell.task([
    'echo test'
]));
tomaoq
  • 3,028
  • 2
  • 18
  • 25
  • 1
    Oh well.. that was easy, and I was bothering my head with it. But it seems rather inconsistent with the rest of the task definitions. Might want to elaborate what's the big difference? :-) – NewGulpUserxx Oct 28 '14 at 08:52
  • 1
    And is there a way to not make it strip colors away from the output? – NewGulpUserxx Oct 28 '14 at 08:54
  • That's just the way it works. I think it has something to do with the way gulp stream's data. I don't think there is a way for the colors to show, maybe try to put your commands in an external script file and launch that file with gulp-shell, just an idea. – tomaoq Oct 28 '14 at 08:58
4

For the record, if you want to pipe gulp-shell, per specified in the doc:

gulp.task('myGulpTask', [], function() {
  return gulp.src('gulpfile.js', {read: false})
    .pipe(shell('echo "This works too"'));
});
Andrew
  • 7,848
  • 1
  • 26
  • 24
  • 1
    This is now considered an anti pattern don't do this - https://github.com/sun-zheng-an/gulp-shell – mzyrc Oct 16 '17 at 09:30