No handles from createProcess

L.S., I am experimenting with the createProcess function from the package "process"; this function does not return any handle, on both Ubuntu and Windows. I am doing something wrong, or is this a bug? (I am using GHC 7.8.3 on both platforms.) The program I am running: ---✂---------------------------------------------- import System.IO import System.Process f = do ( maybeStdinHandel , maybeStdoutHandel , maybeStderrHandel , processHandle ) <- createProcess (proc "cat" ["a.txt"]) case maybeStdinHandel of Just stdinHandel -> do putStrLn "stdin" _ -> putStrLn "No stdin handle" case maybeStdoutHandel of Just stdoutHandel -> do putStrLn "stdout" putStrLn =<< hGetContents stdoutHandel _ -> putStrLn "No stdout handle" case maybeStderrHandel of Just stderrHandel -> do putStrLn "stderr" putStrLn =<< hGetContents stderrHandel _ -> putStrLn "No stderr handle" main = f ---✂---------------------------------------------- The output: ---✂---------------------------------------------- $ ./ProcessTry No stdin handle No stdout handle No stderr handle asdf ---✂---------------------------------------------- (asdf is the contents of file a.txt) Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

On Mon, Dec 15, 2014 at 9:11 AM, Henk-Jan van Tuyl
I am experimenting with the createProcess function from the package "process"; this function does not return any handle, on both Ubuntu and Windows. I am doing something wrong, or is this a bug? (I am using GHC 7.8.3 on both platforms.)
Not a bug; you need to tell it which ones to create handles for. createProcess
http://lambda.haskell.org/platform/doc/current/ghc-doc/libraries/process-1.1... returns (mb_stdin_hdl, mb_stdout_hdl, mb_stderr_hdl, p), where
- if std_in == CreatePipe, then mb_stdin_hdl will be Just h, where h is the write end of the pipe connected to the child process's stdin. - otherwise, mb_stdin_hdl == Nothing
Similarly for mb_stdout_hdl and mb_stderr_hdl.
The default action is to inherit the existing handles for stdin/out/err in the subprocess and provide no handles to the caller; this mirrors the default behavior of creating a new process on Windows and POSIX. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

The documentation for createProcess seems pretty clear on this: if std_in == CreatePipe, then mb_stdin_hdl will be Just h, where h is the write end of the pipe connected to the child process's stdin. otherwise, mb_stdin_hdl == Nothing Similarly for mb_stdout_hdl and mb_stderr_hdl. proc doesn't set std_in to CreatePipe; you need to do that yourself if you need it. On 15/12/14 16:11, Henk-Jan van Tuyl wrote:
L.S.,
I am experimenting with the createProcess function from the package "process"; this function does not return any handle, on both Ubuntu and Windows. I am doing something wrong, or is this a bug? (I am using GHC 7.8.3 on both platforms.)
The program I am running: ---✂---------------------------------------------- import System.IO import System.Process
f = do ( maybeStdinHandel , maybeStdoutHandel , maybeStderrHandel , processHandle ) <- createProcess (proc "cat" ["a.txt"]) case maybeStdinHandel of Just stdinHandel -> do putStrLn "stdin" _ -> putStrLn "No stdin handle" case maybeStdoutHandel of Just stdoutHandel -> do putStrLn "stdout" putStrLn =<< hGetContents stdoutHandel _ -> putStrLn "No stdout handle" case maybeStderrHandel of Just stderrHandel -> do putStrLn "stderr" putStrLn =<< hGetContents stderrHandel _ -> putStrLn "No stderr handle"
main = f ---✂----------------------------------------------
The output: ---✂---------------------------------------------- $ ./ProcessTry No stdin handle No stdout handle No stderr handle asdf ---✂---------------------------------------------- (asdf is the contents of file a.txt)
Regards, Henk-Jan van Tuyl
participants (3)
-
Brandon Allbery
-
Henk-Jan van Tuyl
-
Roman Cheplyaka