Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell: System.Process merge stdout and stderr
    primarykey
    data
    text
    <p>I want to invoke a process from within a haskell program and capture stdout as well as stderr. </p> <p>What I do:</p> <pre><code>(_, stdout, stderr) &lt;- readProcessWithExitCode "command" [] "" </code></pre> <p>The problem: This way, stdout and stderr are captured separately, however I want the messages to appear in the right place (otherwise I would simply <code>stdout ++ stderr</code> which separates error messages from their stdout counterparts).</p> <p>I do know that I could achieve this if I'd pipe the output into a file, i.e.</p> <pre><code>tmp &lt;- openFile "temp.file" ... createProcess (proc "command" []) { stdout = UseHandle tmp, stderr = UseHandle tmp } </code></pre> <p>So my current workaround is to pipe outputs to a tempfile and read it back in. However I'm looking for a more direct approach.</p> <p>If I was on unix for sure I'd simply invoke a shell command á la</p> <pre><code>command 2&gt;&amp;1 </code></pre> <p>and that's it. However, I'd like to have this as portable as possible.</p> <p>What I need this for: I've built a tiny haskell cgi script (just to play with it) which invokes a certain program and prints the output. I want to html-escape the output, thus I can't simply pipe it to stdout.</p> <p>I was thinking: Maybe it's possible to create an in-memory-handle, like a PipedInputStream/PipedOutputStream in Java, or ArrayInputStream/ArrayOutputStream which allows for processing IO streams within memory. I looked around for a function <code>:: Handle</code> on hoogle, but did not find anything.</p> <p>Maybe there is another Haskell module out there which allows me to merge two streams?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload