简体   繁体   English

无法从Yeoman / Node使用spawnCommand获得stdout / stderr

[英]stdout/stderr not available from Yeoman/Node with spawnCommand

For some reason, I cannot capture the output of the following from Yeoman's this.spawnCommand or spawnCommandSync method: 由于某些原因,我无法从Yeoman的this.spawnCommandspawnCommandSync方法捕获以下内容的输出:

const result = this.spawnCommandSync(
  "git",
  ["checkout", "-b", branchName],
  {
    cwd: this.destinationRoot(folderName),
    shell: true
  }
);

console.log(result);

The output of result shows all streams to be null, even when I do something intentionally wrong to get git to throw a "fatal" response: result的输出显示所有流都为null,即使我故意做错了一些事情以使git抛出“致命”响应:

 { status: 128,
  signal: null,
  output: [ null, null, null ],
  pid: 36926,
  stdout: null,
  stderr: null,
  error: null }

My understanding is the above should catch "fatal" error messages thrown by git when a user attempts to do something (for example, clone a repo that does not exist). 我的理解是,当用户尝试执行某项操作(例如,克隆不存在的存储库)时,以上内容应捕获git抛出的“致命”错误消息。

I am trying to collect this information so I can bail out of my Yeoman generator. 我正在尝试收集此信息,以便可以从Yeoman发电机中退出。

How do I do this with Yeoman? 我应该如何用Yeoman做到这一点? Their documentation on spawnCommand and spawnCommandSync don't show much, and I get that they are just wrappers around spawn/spawn sync, which makes it more puzzling to me why the above isn't working for git commands. 他们关于spawnCommand和spawnCommandSync的文档显示不多,我知道它们只是spawn / spawn同步的包装,这使我更加困惑,为什么上面的命令不适用于git命令。 From what I can tell, if I don't specify any stdio options, I should get pipes between the parent/child. 据我所知,如果不指定任何stdio选项,则应该在父/子之间获得管道。 Am I missing something? 我想念什么吗?

Thanks! 谢谢!

我通过在opts中添加以下内容解决了此问题:

stdio: [process.stderr]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 确定服务器返回的输出是流星/节点中客户端上的stderr还是stdout? - Determine if returned output from server is stderr or stdout on client in Meteor/Node? 在node.js 8的child.process中定义stdout和stderr - Defining stdout and stderr in a child.process in node.js 8 捕获在 Electron 中运行的 Node-API 模块的 stdout/stderr - Capturing stdout/stderr of Node-API module running in Electron Node.js spawn:保持 StdOut 和 StdErr 的原始顺序 - Node.js spawn: Keep StdOut and StdErr in the original order 在将child_process.exec用于Node.js时,为什么输出从STDERR而不是STDOUT发出? - Why does output come out from STDERR and not STDOUT when using child_process.exec for Node.js? 如何将 pipe stdout/stderr 从 Deno 的工作人员提交? - How to pipe stdout/stderr to file from worker in Deno? 如何基于stdout和stderr对来自nodejs的角度post调用进行身份验证 - how to authenticate angular post call from nodejs based on stdout and stderr 从 node.js 中的标准输出读取 - reading from stdout in node js Node.js 子进程执行返回:错误:kill EPERM STDERR STDOUT_SIZE - Node.js child process exec returning : Error: kill EPERM STDERR STDOUT_SIZE Node.js child_process.exect stdout 返回 null,但 stderr 没有 - Node.js child_process.exect stdout return null, but stderr did not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM