我如何将进程的标准输出和标准错误输出到同一个句柄? [英] How do I pipe the stdout and stderr of a process to the same Handle?

查看:205
本文介绍了我如何将进程的标准输出和标准错误输出到同一个句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将进程的标准输出和标准错误输出到同一个句柄?在unix系统上它很简单,只需使用 createPipe ,并将写入结束符作为stdout和stderr传递给 runProcess 。在Windows上它很难:


  • 无论是unix-compat还是Win32软件包都不会创建管道。


  • openTempFile (可用于模拟管道)在创建的处理




编辑:提供更多上下文:我想运行一个进程并且以跨平台的方式将它的stdout和stderr写入同一个 Handle

解决方案

您可以使用 System.Process 。在 CreateProcess 定义中,有

  std_in :: StdStream, - ^如何确定stdin 
std_out :: StdStream, - ^如何确定stdout
std_err :: StdStream, - ^如何确定stderr

StdStream 有这个构造函数:

  data StdStream = UseHandle Handle 

然后,将对象形成到 createProcess 函数来运行你的过程。


How do I pipe the stdout and stderr of a process to the same Handle? On unix systems it's pretty easy, just use createPipe and pass the write end to runProcess as both stdout and stderr. On Windows it's harder:

  • Neither the unix-compat nor the Win32 package export a way to create pipes.

  • openTempFile (which could be use to simulate pipes) sets the wrong mode on the created Handle.

Edit: To give some more context: I want to run a process and have it write its stdout and stderr to the same Handle, in a cross-platform manner.

解决方案

You can use stuff from System.Process. In the CreateProcess definition there are

std_in       :: StdStream,               -- ^ How to determine stdin
std_out      :: StdStream,               -- ^ How to determine stdout
std_err      :: StdStream,               -- ^ How to determine stderr

and StdStream have this constructor:

data StdStream = UseHandle Handle

After that, pass the object you formed to the createProcess function to run your proc.

这篇关于我如何将进程的标准输出和标准错误输出到同一个句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆