From d3aad100450b41cf7c3ce2b8656668bcdf477fe5 Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Wed, 7 Nov 2007 08:50:09 +0100 Subject: Add spawnPipe darcs-hash:20071107075009-a5988-a5a816a093890ddc9477ca7d6cb339061256d16d.gz --- XMonad/Util/Run.hs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/XMonad/Util/Run.hs b/XMonad/Util/Run.hs index 25757d5..fad92cd 100644 --- a/XMonad/Util/Run.hs +++ b/XMonad/Util/Run.hs @@ -24,16 +24,18 @@ module XMonad.Util.Run ( unsafeSpawn, runInTerm, safeRunInTerm, - seconds + seconds, + spawnPipe ) where import Control.Monad.Reader +import System.Posix.IO import System.Posix.Process (createSession, forkProcess, executeFile, getProcessStatus) import Control.Concurrent (threadDelay) import Control.Exception (try) import System.Exit (ExitCode(ExitSuccess), exitWith) -import System.IO (IO, FilePath, hPutStr, hGetContents, hFlush, hClose) +import System.IO import System.Process (runInteractiveProcess, waitForProcess) import XMonad @@ -114,3 +116,19 @@ safeRunInTerm command = asks (terminal . config) >>= \t -> safeSpawn t ("-e " ++ unsafeRunInTerm, runInTerm :: String -> X () unsafeRunInTerm command = asks (terminal . config) >>= \t -> unsafeSpawn $ t ++ " -e " ++ command runInTerm = unsafeRunInTerm + +-- | Launch an external application and return a 'Handle' to its standard input. +spawnPipe :: String -> IO Handle +spawnPipe x = do + (rd, wr) <- createPipe + setFdOption wr CloseOnExec True + h <- fdToHandle wr + hSetBuffering h LineBuffering + pid <- forkProcess $ do + forkProcess $ do + dupTo rd stdInput + createSession + executeFile "/bin/sh" False ["-c", x] Nothing + exitWith ExitSuccess + getProcessStatus True False pid + return h -- cgit v1.2.3