git clone的child_process中的stdout不输出下载进度

时间:2019-07-24 03:21:27

标签: javascript node.js child-process

我想在Javascript中下载一个git存储库。 到目前为止,我有以下内容:

app.post('/shell', function (req, res, next) {
  res.writeHead(200, {
    'Connection': 'Transfer-Encoding',
    'Content-Type': 'text/plain charset=utf-8',
    'Transfer-Encoding': 'chunked',
    'X-Content-Type-Options': 'nosniff'
  })

  const child = spawn(req.body.command, req.body.flags, {stdio: 'pipe'})
  child.stdout.setEncoding('utf8')
  child.stdout.on('data', (chunk) => {
    console.log(chunk)
    res.write(chunk)
    res.flush()
  })

  child.stderr.on('data', (chunk) => {
    console.log(chunk)
    res.write(chunk)
    res.flush()
  })

  child.on('close', (code) => {
    console.log(`child process exited with code ${code}`);
    res.end('Finished running commands!')
  })
})

我执行git clone http://...,但仅以Cloning into 'xyz'...的形式获得输出stderr。我可以以某种方式访问​​打印到终端上的进度更新吗?

0 个答案:

没有答案