dshgdhdfcas30210 2015-03-11 22:57
浏览 135
已采纳

exec.command设置输出流未获取所有数据

This works

res = exec.Command(gitCmd, cmdArgs...)
res.Stdout, res.Stderr = os.Stdout,os.Stderr

When executing a git command like git clone .. you get full syntax response like

remote: Counting objects: 15, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 15 (delta 4), reused 0 (delta 0)
Receiving objects: 100% (15/15), done.
Resolving deltas: 100% (4/4), done.

BUT if you wrap it in a multiwriter like this

res = exec.Command(gitCmd, cmdArgs...)
res.Stdout, res.Stderr = io.MultiWriter(os.Stdout),io.MultiWriter(os.Stderr)

You lose all the resolving / receiving outputs, that you normally see. Why ?

The following works but to me seems unnecessary, IMHO the io.MultiWriter should do the same ...

res = exec.Command(gitCmd, cmdArgs...)
res.Stdout, res.Stderr = os.Stdout,os.Stderr
stdout, stderr = new(bytes.Buffer), new(bytes.Buffer)
go io.Copy(os.Stdout,stdout)
go io.Copy(os.Stderr,stderr)
  • 写回答

1条回答 默认 最新

  • doujiu4643 2015-03-11 23:39
    关注

    The difference is the TTY. Using a MultiWriter (or anything else) would break the TTY. If you want to do so, you need to use a PTY master/slave pair. You can take a look at https://github.com/kr/pty for more info.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测