2013-03-26 32 views
1

我想通过Node.js的做到这一点:管加工提取焦油缓冲区Node.js的子进程

git archive [email protected]:repo.git HEAD | tar -x - -C /path/to/extracted/ 

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

git = spawn 'git', ['archive', "[email protected]: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

正确的命令其实并不需要和-C-之间-x

git archive [email protected]:repo.git HEAD | tar -x -C /path/to/extracted/ 

回答

1

你应该使用函数exec和在这种情况下,不产卵。如在exec文档中所见,它接受管道exec documentation

exec('git archive [email protected]:repo.git HEAD | tar -x - -C /path/to/extracted/', function (error, stdout, stderr) { 
    // logic here 
} 
+0

欢呼声。我会稍后再试! – Japboy 2013-03-26 16:32:19

+0

工程就像一个魅力!谢谢!!! – Japboy 2013-03-27 05:41:57