Gabriella439 / turtle

Shell programming, Haskell style

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling subprocess speaking in non-UTF8

ulysses4ever opened this issue · comments

Here is an artificial example simplifying a real-world scenario:

{-# LANGUAGE OverloadedStrings #-}

module Main where

import Turtle
import Prelude hiding (FilePath)
import qualified Data.Text.IO as TSIO

main :: IO ()
main = sh $ do
  (_exitCode, outRaw, _errRaw) <-
      procStrictWithErr "env" ["printf",  "\\273"] (select [])  -- 273 in oct is 187 in dec
  liftIO $ TSIO.putStrLn outRaw

This fails with:

app: fd:5: hGetContents: invalid argument (invalid byte sequence)

In fact, I have a more complicated subprocess returning bytes with decimal values greater than 127. I need to get the process' output and after some processing store it to a file. Is there a reasonable way to handle this use case with Turtle?

@ulysses4ever: There is a Turtle.Bytes module which handles arbitrary byte streams

Oh, indeed. Thanks a lot!

@ulysses4ever: You're welcome! 🙂