10
使用Node的child_process
模塊,我想通過cygwin shell執行命令。這就是我想:執行NodeJS的cygwin命令
var exec = require('child_process').execSync;
exec('mkdir -p a/b/c', {shell : 'c:/cygwin64/bin/bash.exe -c'});
TypeError: invalid data at WriteStream.Socket.write (net.js:641:11) at execSync (child_process.js:503:20) at repl:1:1 at REPLServer.defaultEval (repl.js:262:27) at bound (domain.js:287:14) at REPLServer.runBound [as eval] (domain.js:300:12) at REPLServer. (repl.js:431:12) at emitOne (events.js:82:20) at REPLServer.emit (events.js:169:7) at REPLServer.Interface._onLine (readline.js:212:10)
我可以看到Node's child_process.js will add the /s
and /c
switches,無論是集shell
選項,bash.exe不知道如何處理這些論點做。
我找到了一個工作,圍繞這個問題,但它確實不理想:
exec('c:/cygwin64/bin/bash.exe -c "mkdir -p a/b/c"');
做上述顯然只能在Windows不是Unix系統上運行。
如何在NodeJS的cygwin shell中執行命令?