aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpencer Janssen <sjanssen@cse.unl.edu>2007-11-07 08:50:09 +0100
committerSpencer Janssen <sjanssen@cse.unl.edu>2007-11-07 08:50:09 +0100
commitd3aad100450b41cf7c3ce2b8656668bcdf477fe5 (patch)
treef4cbf11d5d1752b84d3629169eb14d04723caddf
parent39cf1c8869bb6d4bc2553ba78433ef33df8316f0 (diff)
downloadXMonadContrib-d3aad100450b41cf7c3ce2b8656668bcdf477fe5.tar.gz
XMonadContrib-d3aad100450b41cf7c3ce2b8656668bcdf477fe5.tar.xz
XMonadContrib-d3aad100450b41cf7c3ce2b8656668bcdf477fe5.zip
Add spawnPipe
darcs-hash:20071107075009-a5988-a5a816a093890ddc9477ca7d6cb339061256d16d.gz
-rw-r--r--XMonad/Util/Run.hs22
1 files 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