Responding to the list..<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Benjamin Edwards</b> <span dir="ltr">&lt;<a href="mailto:edwards.benj@gmail.com">edwards.benj@gmail.com</a>&gt;</span><br>
Date: 11 August 2012 17:37<br>Subject: Re: [Haskell-cafe] hGetContents Illegal byte sequence / ghc-pkg<br>To: David McBride &lt;<a href="mailto:toad3k@gmail.com">toad3k@gmail.com</a>&gt;<br><br><br>Thank you Gents,<div><br>
</div><div>Most useful. One thing that had escaped me is that of course, even if hGetContents and friends are respecting *my* locale, I have a binary distro and the package database probably isn&#39;t in my locale. I will try and find that.</div>

<div><br></div><div>Thanks,</div><div> Ben<div><div class="h5"><br><br><div class="gmail_quote">On 11 August 2012 15:26, David McBride <span dir="ltr">&lt;<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I had this same problem a couple weeks ago when trying to install virthualenv and I don&#39;t really understand it got into a bad state, but the way I solved it was by fixing the locale settings on my gentoo machine so that I&#39;m using UTF8.  That just involved a few changes in /etc and then the problem went away.<br>


<br><div class="gmail_quote"><div>On Sat, Aug 11, 2012 at 7:13 AM, Benjamin Edwards <span dir="ltr">&lt;<a href="mailto:edwards.benj@gmail.com" target="_blank">edwards.benj@gmail.com</a>&gt;</span> wrote:<br></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
Hello café,<div><br></div><div>I have a program that is crashing, and I have no idea why:</div><div><br></div><div><div>module Main</div><div>  where</div><div><br></div><div>import System.Process (readProcessWithExitCode)</div>



<div><br></div><div><br></div><div>main :: IO ()</div><div>main = do _ &lt;- readProcessWithExitCode &quot;ghc-pkg&quot; [&quot;describe&quot;, &quot;hoopl&quot;] &quot;&quot;</div><div>          putStrLn &quot;Should never get here&quot;</div>



</div><div><br></div><div>this is using the process package from hackage. The program crashes with </div><div><br></div><div><div>minimal-test: fd:5: hGetContents: invalid argument (invalid byte sequence)</div><div>minimal-test: thread blocked indefinitely in an MVar operation</div>



</div><div><br></div><div>inspecting the source of readProcessWithExitCode yields an obvious explanation to the MVar problem, but I don&#39;t understand why hGetContents is so offended.</div><div><br></div><div>For the lazy it is defined as follows:</div>



<div><br></div><div><div>readProcessWithExitCode</div><div>    :: FilePath                 -- ^ command to run</div><div>    -&gt; [String]                 -- ^ any arguments</div><div>    -&gt; String                   -- ^ standard input</div>



<div>    -&gt; IO (ExitCode,String,String) -- ^ exitcode, stdout, stderr</div><div>readProcessWithExitCode cmd args input = do</div><div>    (Just inh, Just outh, Just errh, pid) &lt;-</div><div>        createProcess (proc cmd args){ std_in  = CreatePipe,</div>



<div>                                       std_out = CreatePipe,</div><div>                                       std_err = CreatePipe }</div><div><br></div><div>    outMVar &lt;- newEmptyMVar</div><div><br></div><div>    -- fork off a thread to start consuming stdout</div>



<div>    out  &lt;- hGetContents outh</div><div>    _ &lt;- forkIO $ C.evaluate (length out) &gt;&gt; putMVar outMVar ()</div><div><br></div><div>    -- fork off a thread to start consuming stderr</div><div>    err  &lt;- hGetContents errh</div>



<div>    _ &lt;- forkIO $ C.evaluate (length err) &gt;&gt; putMVar outMVar ()</div><div><br></div><div>    -- now write and flush any input</div><div>    when (not (null input)) $ do hPutStr inh input; hFlush inh</div><div>



    hClose inh -- done with stdin</div><div><br></div><div>    -- wait on the output</div><div>    takeMVar outMVar</div><div>    takeMVar outMVar</div><div>    hClose outh</div><div>    hClose errh</div><div><br></div><div>



    -- wait on the process</div><div>    ex &lt;- waitForProcess pid</div><div><br></div><div>    return (ex, out, err)</div></div><div><br></div><div>Now having looked at the source of ghc-pkg it is dumping it&#39;s output using putStr and friends, so that should be using my local encoding on the system, right? and so should hGetContents in my program..?</div>



<div><br></div><div>Now, for the curious: the reason I care is that this problem has effectively prevented me from using virthualenv. Sadness and woe.</div>
<br></div></div><div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></div></blockquote></div><br>
</blockquote></div><br></div></div></div>
</div><br>