我想從gulp運行shell命令,使用gulp-shell
。我看到以下習語被使用了大文件。從gulp運行shell命令
這是從一個吞嚥任務運行命令的慣用方式?
var cmd = 'ls';
gulp.src('', {read: false})
.pipe(shell(cmd, {quiet: true}))
.on('error', function (err) {
gutil.log(err);
});
我想從gulp運行shell命令,使用gulp-shell
。我看到以下習語被使用了大文件。從gulp運行shell命令
這是從一個吞嚥任務運行命令的慣用方式?
var cmd = 'ls';
gulp.src('', {read: false})
.pipe(shell(cmd, {quiet: true}))
.on('error', function (err) {
gutil.log(err);
});
gulp-shell
已被列入黑名單。您應該使用gulp-exec,這也有更好的文檔。
對於你的情況,它實際上指出:
注意:如果你只是想運行一個命令,只需運行命令,不要使用這個插件:
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);
});
})
的新的方式來做到這一點,保持控制檯輸出相同(例如,用顏色):
請參閱:https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
var gulp = require('gulp');
var spawn = require('child_process').spawn;
gulp.task('my-task', function (cb) {
var cmd = spawn('cmd', ['arg1', 'agr2'], {stdio: 'inherit'});
cmd.on('close', function (code) {
console.log('my-task exited with code ' + code);
cb(code);
});
});
但如果你是在Windows上,爲產卵()不正常,請參閱[這個節點問題(HTTPS小心://GITH ub.com/nodejs/node-v0.x-archive/issues/2318) –
這是最好的答案海事組織+1 – chukkwagon
隨着gulp 4你的任務可以直接返回一個子進程的信號任務完成:
'use strict';
var cp = require('child_process');
var gulp = require('gulp');
gulp.task('reset', function() {
return cp.execFile('git checkout -- .');
});
https://github.com/gulpjs/gulp/blob/4.0/docs/recipes/running-shell-commands.md
注意,吞下4還沒有正式發佈。 – Narretz
Gulp 4是芝諾悖論的現代化身。 –
如何執行兩個shell命令? –
'gulp-shell已被列入黑名單':你是什麼意思? – Laoujin
Gulp提供了一個黑名單,它不是用「Gulp方式」編寫的。看看這裏的列表:https://github.com/gulpjs/plugins/blob/master/src/blackList.json – ddprrt