javascript - Gulp how to save output to file - Stack Overflow

I am using gulp and gulp-shell. How do I save output to a file (created by gulp) ?return gulp.src('

I am using gulp and gulp-shell. How do I save output to a file (created by gulp) ?

return gulp.src('.')
    .pipe(shell([
        'poser install --prefer-source'
    ]));

I am using gulp and gulp-shell. How do I save output to a file (created by gulp) ?

return gulp.src('.')
    .pipe(shell([
        'poser install --prefer-source'
    ]));
Share Improve this question edited Nov 13, 2014 at 21:12 Sean Mickey 7,7262 gold badges34 silver badges58 bronze badges asked Nov 13, 2014 at 21:05 ThomasThomas 5451 gold badge13 silver badges22 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

To achieve this I use gulp-exec.

gulp.task("git_log", [], function(){
    var options = {
        continueOnError: false, // default = false, true means don't emit error event
        pipeStdout: true, // default = false, true means stdout is written to file.contents
        customTemplatingThing: "test" // content passed to gutil.template()
    };
    var reportOptions = {
        err: false, // default = true, false means don't write err
        stderr: true, // default = true, false means don't write stderr
        stdout: false // default = true, false means don't write stdout
    };
    return gulp.src("somefile.txt")
        .pipe(exec("pwd", options))
        .pipe(exec.reporter(reportOptions))
        .pipe(gulp.dest('build/'));
});

continue with .pipe(gulp.dest('output.file')).

Gulp Shell passes files not the output of the mands it runs.

A quick and dirty solution — that is not windows friendly nor gulp based — would be to simply pass the output of the shell mand to a file within the mand itself:

return gulp.src('.')
  .pipe(shell([
    'poser install --prefer-source > poser-log.txt'
  ]));

This is obviously only suitable for *nix environments, and doesn't scale well for capturing the output of multiple mands (although you could just append the output from all those mands to the same file).

You could better use run to do this.

gulp.task 'run',->
run ("echo Hello!")
.exec()
.pipe (gulp.dest "G:\\new.txt")

Install needed plugins for this like gulp-run and gulp-exec.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745411152a4626539.html

相关推荐

  • javascript - Gulp how to save output to file - Stack Overflow

    I am using gulp and gulp-shell. How do I save output to a file (created by gulp) ?return gulp.src('

    4小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信