2016-08-04 47 views
1

使用ls之類簡單的命令,PWD,甚至打開外部應用程序,我用的子進程有成功,但使用EXEC在內置電子應用泊塢窗命令時,我得到這個錯誤:child_process不能執行搬運工人運行

exec Error: Command failed: docker exec -it 6bec55e9e86e touch home.html 
the input device is not a TTY 

下面是代碼:

var exec = require('child_process').exec; 

exec('docker exec -it 6bec55e9e86e touch casa.html', function (error, stdout, stderr) { 
    console.log('stdout: ' + stdout); 
    console.log('stderr: ' + stderr); 
    if (error !== null) { 
    console.log('exec error: ' + error); 
    } 
}); 

回答

-1

使用spawn並設置options.stdioinherit將工作:

const spawn = require('child_process').spawn; 
spawn('docker', ['exec', '-it', '6bec55e9e86e', 'touch', 'casa.html'], { stdio: 'inherit' }) 
+0

我試過了。我沒有成功! – calebeaires

2

請刪除-t標誌。所以你的命令應該是docker exec -i 6bec55e9e86e touch casa.html

此錯誤the input device is not a TTY表示您的輸入設備不是Teletypes(終端),並且在docker的命令中,標記符號爲-t,因此它們有衝突。所以只要刪除它。