2013-03-26 33 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