1

I'm trying to run a command interactively from my build script:

#!/usr/bin/env stack
{- stack
script
--resolver lts-18.8
--ghc-options -Wall
-}
import Development.Shake

main :: IO ()
main = shakeArgs shakeOptions $ do
  phony "cfg" $ do
    command_ [] "vim" []

But it does not work. I suppose I need to allocate a terminal to be able to run vim interactively. How can I do that?

carbolymer
  • 1,439
  • 1
  • 15
  • 30
  • For which operating system ??? On Linux, if your process cannot be run in a terminal passed from above, you would typically use something like `xterm -e /bin/bash -c "/usr/bin/vim fileName"`. Can be improved by telling xterm which font to use, etc... – jpmarinier Aug 29 '21 at 20:07

1 Answers1

2

The Shake functions for running commands (command, cmd etc) are designed for batch commands that run without user interaction. While there are things you can do to make them more compatible with something like Vim (e.g. InheritStdin) there are probably aspects of Shake that will make things harder (e.g. capturing the stderr, which might result in a memory leak).

Happily, Shake can work just as well with the functions in System.Process, so instead of calling command you can write:

liftIO $ System.Process.createProcess $ System.Process.shell "vim"

The createProcess takes a record with many types of process-related settings, so can be customised to make Vim work.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85
  • 1
    Yeah, that's what I did in the end: `createProcess $ proc "vim" [] >>= \(_, _, _, ph) -> waitForProcess ph`. Thanks for the explanation. – carbolymer Aug 31 '21 at 19:51