12

I'm trying to build a jekyll site using Gulp.js. I've read that I shouldn't use a plugin in this question.

I've been investigating using a child process as suggested but I keep getting an error:

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)

Here's my gulp file:

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']);

What am I doing wrong? I'm on Node 0.10.25, Win 7.

EDIT I've had a google around ENOENT errors previously. Have checked my path and Ruby is there and I can run jekyll from the command line. Still no joy.

4

3 回答 3

15

我也遇到了这个问题,并找到了使用 spawn 的答案。

问题在于 Node 如何在 Windows 上找到可执行文件。有关更多详细信息,请查看此答案:

https://stackoverflow.com/a/17537559

简而言之,为了让 spawn 工作,更改spawn('jekyll', ['build'])为。spawn('jekyll.bat', ['build'])

于 2014-05-25T05:30:51.907 回答
9

所以我最终exec改用了。这是我的 gulp 文件:

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);
});
});

这是一篇关于差异的帖子

于 2014-02-18T16:41:43.183 回答
1

几年后,您现在可以使用cross-spawn,它可以解决 node 的跨平台问题spawn。它是 Node 的直接替代品spawn

安装到您的项目中

npm install cross-spawn

然后加

const spawn = require('cross-spawn');

到你的脚本。

然后在你的 gulp 脚本中正常使用:

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

如果您在非 gulp 脚本中使用它:

var jekyll = spawn('bundle exec jekyll build');
于 2018-09-08T09:17:36.860 回答