Skip to content

Instantly share code, notes, and snippets.

@romanofski
Created April 16, 2019 10:24
Show Gist options
  • Save romanofski/d30be6bcd7250756995088de0ee3a5f7 to your computer and use it in GitHub Desktop.
Save romanofski/d30be6bcd7250756995088de0ee3a5f7 to your computer and use it in GitHub Desktop.
test reproducer for exec/bash tempfile
#!/bin/sh
sleep 1
set -e
cat $1
#!/bin/sh
exec /tmp/bar.sh "$@"
{-# LANGUAGE OverloadedStrings #-}
import System.IO.Temp (withSystemTempFile, emptySystemTempFile)
import System.IO (hClose)
import System.Directory (removeFile)
import System.Process.Typed (readProcessInterleaved_, proc)
import Control.Monad (void)
import qualified Data.ByteString as B
main :: IO ()
main = usingWSTF
normal :: IO ()
normal = do
fn <- emptySystemTempFile "tmptest"
B.writeFile fn "<h1>Foo</h1>"
print ("wrote " <> fn)
out <- readProcessInterleaved_ (proc "/tmp/foo.sh" [fn])
print out
removeFile fn
usingWSTF :: IO ()
usingWSTF = void $ withSystemTempFile "tmptest" $ \fn h -> do
B.hPut h "<h1>Foo</h1>"
hClose h
print ("wrote " <> fn)
out <- readProcessInterleaved_ (proc "/tmp/foo.sh" [fn])
print out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment