无法在Windows上写入产生的child_process的stdin
下面的代码可以在Linux上正常工作,但是在Windows 7上会中断
var spawn = require('child_process').spawn; var sass = spawn('sass'); sass.stdout.on('data', function (data) { console.log('' + data); }); sass.stdin.write('.asdfsadf\n color: red', function () { sass.stdin.end() });
我得到的错误是
events.js:72 throw er; // Unhandled 'error' event ^ Error: This socket is closed. at Socket._write (net.js:637:19) at doWrite (_stream_writable.js:226:10) at writeOrBuffer (_stream_writable.js:216:5) at Socket.Writable.write (_stream_writable.js:183:11) at Socket.write (net.js:615:40) at Object.<anonymous> (e:\Projects\scaffold-angular\test.js:18:12) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12)
我已经用slimrb
试过这个,同样的“套接字已closures”错误。
当我在控制台上手动input命令时,所有的命令都可以find(同时尝试了MINGW32和普通的windows命令行)。
$ sass .asdfsadf color: red ^Z .asdfsadf { color: red; }
我的节点是v0.10.28
编辑:更新至v0.10.29
,同一问题:(
您可以使用cross-spawn
软件包作为child_process.spawn
替代child_process.spawn
。