2014-02-18 40 views
12

我試圖建立一個使用Gulp.js的jekyll站點。我讀過,我不應該在this question中使用插件。運行jekyll作爲一個孩子進程中的一攬子/節點

我一直在使用一個子進程的建議一直在調查,但我不斷收到一個錯誤:

events.js:72 
    throw er; // Unhandled 'error' event 
     ^
Error: spawn ENOENT 
    at errnoException (child_process.js:988:11) 
    at Process.ChildProcess._handle.onexit (child_process.js:779:34) 

這是我一飲而盡文件:

var gulp = require('gulp'); 
var spawn = require('child_process').spawn; 
var gutil = require('gulp-util'); 

gulp.task('jekyll', function(){ 
    spawn('jekyll', ['build'], {stdio: 'inherit'}); 
}); 

gulp.task('default', ['jekyll']); 

我在做什麼錯?我在節點0.10.25,贏7。

編輯 我以前有一個谷歌ENOENT錯誤。已經檢查了我的路徑,Ruby在那裏,我可以從命令行運行jekyll。仍然沒有快樂。

回答

14

我也有這個問題,並找到了答案,用產卵。

問題在於Node如何在Windows上找到可執行文件。欲瞭解更多詳細看這個答案:

https://stackoverflow.com/a/17537559

總之,爲了獲得重生工作變動spawn('jekyll', ['build'])spawn('jekyll.bat', ['build'])

+0

SpikeMeister,我只是看到你的答案搜索我自己的問題。對不起,沒有接受,並提前投票。 您是否知道.bat修補程序可在Mac/Unix機器上使用? 讓我的一天! – matthewbeta

+2

重新我以前的評論。您可以根據操作系統設置命令: 'var jekyll = process.platform ===「win32」? 「jekyll.bat」:「jekyll」;' 然後運行: 'spawn(jekyll'['build'])'' – matthewbeta

8

所以我最終使用exec來代替。這是我的一飲而盡文件:

var gulp = require('gulp'); 
var exec = require('child_process').exec; 
var gutil = require('gulp-util'); 

gulp.task('jekyll', function(){ 
exec('jekyll build', function(err, stdout, stderr) { 
    console.log(stdout); 
}); 
}); 

Here's a post about the differences

相關問題