The problem occurs because the child gulp script requires working directory change:
gulp --gulpfile "<...>\gulpfile.js" build
[13:40:01] Working directory changed to <...>
[13:40:03] Using gulpfile <...>\gulpfile.js
[13:40:03] Starting 'build'...
[13:40:03] Finished 'build' after 6.42 μs
This works:
const cp = require('cp');
gulp.task('gg2', function (done) {
var gulpfile = path.join(gulpcwd, 'gulpfile.js');
var subShell = cp.spawn('cmd.exe', ['/C', 'gulp', '--gulpfile', gulpfile, '--cwd', gulpcwd, 'build'], {
env: process.env,
cwd: process.cwd()
});
subShell.stdout.pipe(process.stdout);
subShell.stderr.pipe(process.stderr);
subShell.once('exit', function (code) {
done(code);
});
});
The problem occurs because the child gulp script requires working directory change: gulp --gulpfile "<...>\gulpfile.js" build [13:40:01] Working directory changed to <...> [13:40:03] Using gulpfile <...>\gulpfile.js [13:40:03] Starting 'build'... [13:40:03] Finished 'build' after 6.42 μs
This works:
This doesn’t work:
In latter case the child process sends a standard gulp error that the gulp file is not found.