Created
April 16, 2019 10:24
-
-
Save romanofski/d30be6bcd7250756995088de0ee3a5f7 to your computer and use it in GitHub Desktop.
test reproducer for exec/bash tempfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
sleep 1 | |
set -e | |
cat $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec /tmp/bar.sh "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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