我想在gulp.watch
函数末尾添加一些bash命令来加快我的开发速度。所以,我想知道是否有可能。谢谢!如何在gulp中运行bash命令?
49
A
回答
45
使用https://www.npmjs.org/package/gulp-shell。
一个方便的命令行界面一饮而尽
74
我会去:
var spawn = require('child_process').spawn;
var fancyLog = require('fancy-log');
var beeper = require('beeper');
gulp.task('default', function(){
gulp.watch('*.js', function(e) {
// Do run some gulp tasks here
// ...
// Finally execute your script below - here "ls -lA"
var child = spawn("ls", ["-lA"], {cwd: process.cwd()}),
stdout = '',
stderr = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
stdout += data;
fancyLog(data);
});
child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
stderr += data;
fancyLog.error(data));
beeper();
});
child.on('close', function(code) {
fancyLog("Done with exit code", code);
fancyLog("You access complete stdout and stderr from here"); // stdout, stderr
});
});
});
真的没什么“大口”,在这里 - 主要是利用子进程http://nodejs.org/api/child_process.html和结果欺骗成花式登录
0
最简单的办法是那么容易,因为:
var child = require('child_process');
var gulp = require('gulp');
gulp.task('launch-ls',function(done) {
child.spawn('ls', [ '-la'], { stdio: 'inherit' });
});
它不使用节点流和咽管,但它会做的工作。
相关问题
- 1. 如何用gulp运行hbfsy命令?
- 2. 运行bash命令
- 3. 如何运行命令行(bash)的
- 4. 如何定期运行bash命令?
- 5. 在su命令中运行bash函数
- 6. 在Python中运行BASH内置命令?
- 7. 在BASH中运行变量命令
- 8. Android在应用中运行bash命令
- 9. 在bash脚本中运行hadoop命令
- 10. 在curl语句中运行bash命令
- 11. 在heroku bash中运行golang命令
- 12. bash命令在新的命令行窗口中运行程序
- 13. 如何在package.json的Windows命令行(bash,babun)中运行2 npm命令?
- 14. 永久运行gulp watch命令
- 15. 运行bash命令从PHP
- 16. Bash命令echo不运行
- 17. 如何在python中运行多行bash命令?
- 18. sqlplus oracle:如何在1行中的bash上运行sql命令?
- 19. 如何在Kotlin中执行bash命令
- 20. Bash无法识别gulp命令
- 21. 在bash上在ssh上运行命令
- 22. Bash脚本并在命令行上手动运行命令
- 23. 如何在bash中找到运行命令的PID?
- 24. 如何以root身份在bash中运行命令?
- 25. 如何在Python脚本中运行bash命令?
- 26. 如何在使用bash的目录列表中运行命令?
- 27. 如何在bash脚本中运行这两个heroku命令?
- 28. 在bash命令中执行
- 29. 如何运行一个用于在bash命令行根上环
- 30. 如何在Mac bash上从命令行运行Gradle
虽然还有其他方法(如gulp-exec和gulp-spawn),但gulp-shell立即打印命令的输出 - 这是通常需要的。 – jmu
现在还有['gulp-run'](https://www.npmjs.com/package/gulp-run),它有一个更清洁和更直观的界面IMO。 –
gulp-shell被列入黑名单,请参阅https://github.com/gulpjs/plugins/blob/master/src/blackList.json。 –