【问题标题】:nodejs child_process only get emptynodejs child_process 只会为空
【发布时间】:2017-04-09 00:52:53
【问题描述】:

当我为 cmd 使用 child_process exec/spawn 时

  • git gc
  • git fsck --full

stdout/stderr 只会得到''

但它应该返回

$ git gc
Counting objects: 284, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (99/99), done.
Writing objects: 100% (284/284), done.
Total 284 (delta 169), reused 284 (delta 169)

$ git fsck --full
Checking object directories: 100% (256/256), done.
Checking objects: 100% (284/284), done.

这里有什么问题 我怎么得到它

【问题讨论】:

    标签: node.js git


    【解决方案1】:

    Git 输出到标准错误而不是标准输出。 您必须将其重定向到标准输出才能看到它

    git fsck --full | output.txt 2>&1
    

    而不是通过fs.readFile...在你的nodeJs应用程序中获取output.txt的内容

    【讨论】:

      猜你喜欢
      • 2014-02-03
      • 2013-09-24
      • 1970-01-01
      • 1970-01-01
      • 2016-04-30
      • 2019-06-05
      • 2016-06-07
      • 2020-12-12
      • 1970-01-01
      相关资源
      最近更新 更多