我在Windows10中使用GitBash,希望在child\u process.exec调用中执行git命令。我想既然我是通过“gitforwindows”安装git的,我只需要将shell指定为GitBash可执行文件。我尝试了GitBash可执行文件路径的所有变体,但总是失败。节点要查找的路径是什么?
c:/program files/git/usr/bin/bash
c:/program\ files/git/usr/bin/bash
/c/program\ files/git/usr/bin/bash
c:\\program files\\git\\usr\\bin\\bash
const { expect } = require('chai');
const { exec } = require('child_process');
describe.only('exec', function(){
it('should work', function(done){
let shellPath = "c:\\program files\\git\\usr\\bin\\bash";
expect(exec(`cat <<< "abc"`, { shell: shellPath }, (err, stdout) => {
expect(err).to.be.null;
expect(stdout.trim()).to.be.equal("abc");
done();
}));
});
});
第一个断言失败:
expected [Error: Command failed: cat <<< "abc" << was unexpected at this time.] to be null