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 }
- nodejspipe道https响应request.post和写入文件
- node.js中的额外stdiostream是否被child_process.spawn阻塞?
- 进程replace – Node.js child_process
- Node.jsstream是否计入您的虚拟主机stream量带宽分配?
- 如何获取node.js zlib gunzippipe道工作?
- 如何将.npmignore目录中的单个文件列入白名单?
- node.js:如何pipe道 – YouTube的MP4到MP3
- 在pipe道未启动后,nodejsstream完成callback
- 问题与Node.js和child_process.exec参数