How do I use the output of readProcess in an xmonad keybinding?
<p>Ok, so some time ago I was thinking of basing the effect of a keybinding in my xmonad based on the output of a script on my box. I eventually decided not to do that for unrelated reasons but I did recently try to do something similar just as an exercise in learning Haskell.</p>

<p>So, given the function:</p>

<pre><code>test = readProcess "echo" ["-n", "gvim"] []
</code></pre>

<p>This throws up because test returns IO String and spawn expects a String.</p>

<pre><code>((modm, xK_y), spawn ("xmessage " ++ test))
</code></pre>

<p>Ok. That's cool. I get it that IO operations are unpredictable and so they should be kept separate. Fine. So I did some poking around online and got to this (dropped the xmessage and just want to pass the output of test by itself):</p>

<pre><code>((modm, xK_y), liftIO test &gt;&gt;= spawn)
</code></pre>

<p>This is worse. It annoyingly compiles but nothing happens when I try out the binding. (I also replaced it with just spawn "xmessage test" and that worked)</p>

<p>So, then I thought "Maybe there's something wrong with my function" so I repl it but from GCHi I get "gvim" which is correct. So then I write it to a haskell file:</p>

<pre><code>main = test &gt;&gt;= putStrLn
test = readProcess "echo" ["-n", "gvim"] []
</code></pre>

<p>Also works correctly.</p>

<p>So, where did I go wrong?</p>

<p>EDIT: Solution was to use <code>runProcessWithInput</code> instead of <code>readProcess</code>. 
Related link: <a href="https://ghc.haskell.org/trac/ghc/ticket/5212" rel="nofollow noreferrer">https://ghc.haskell.org/trac/ghc/ticket/5212</a> <a href="https://stackoverflow.com/questions/26562522/xmonad-io-binding-not-working">xmonad io binding not working</a></p>