pipe理处理以提取Node.jssubprocess中的tar缓冲区

我想通过Node.js来做到这一点:

git archive remote=git@example.com:repo.git HEAD | tar -x - -C /path/to/extracted/ 

所以,我写了这样的代码:

 git = spawn 'git', ['archive', "--remote=git@example.com:repo.git", 'HEAD'] tar = spawn 'tar', ['-x', '-', '-C /path/to/extracted'] git.stderr.on 'data', (data) -> console.log "git error: #{data}" git.stdout.on 'data', (data) -> tar.stdin.write data tar.stderr.on 'data', (data) -> console.log "tar error: #{data}" git.on 'exit', (code) -> console.log "git process done with code #{code}" tar.on 'exit', (code) -> console.log "tar process done with code #{code}" 

然而,这并不像我预期的那样工作。 我应该改变什么才能使这个工作正常?

提前致谢。

UPDATE

正确的命令实际上不需要--x-C之间

 git archive remote=git@example.com:repo.git HEAD | tar -x -C /path/to/extracted/ 

在这种情况下,你应该使用函数exec而不是spawn。 从exec文档中可以看到,它接受pipe理exec文档

 exec('git archive remote=git@example.com:repo.git HEAD | tar -x - -C /path/to/extracted/', function (error, stdout, stderr) { // logic here }