【问题标题】:child_process cant execute docker runchild_process 无法执行 docker run
【发布时间】:2016-12-10 15:46:38
【问题描述】:

使用简单的命令(如 ls、pwd 甚至打开外部应用程序)我可以成功使用子进程,但是在构建的电子应用程序中使用 exec 和 docker 命令时,我收到此错误:

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);
  }
});

【问题讨论】:

    标签: docker electron


    【解决方案1】:

    请删除-t 标志。所以你的命令应该是docker exec -i 6bec55e9e86e touch casa.html

    此错误the input device is not a TTY 表示您的输入设备不是 Teletypes(终端),并且在 docker 的命令中,-t 标志符号为 terminal,因此它们是冲突的。所以只需删除它。

    【讨论】:

      【解决方案2】:

      使用spawn 并将options.stdio 设置为inherit 将起作用:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多