Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack ghci: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory) #3958

Closed
chrissound opened this issue Apr 8, 2018 · 2 comments

Comments

@chrissound
Copy link

Apologies in advance, the example is not a minimal amount of code - but there is quite a few things going on so slimming it down might take some time... None the less I thought I'd report this.

I've written some code that works correctly when using ghci within a process. If I switch to use stack ghci I get the following behaviour:

stack exec app                            
"Stapp: stack ghci: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
arted
stack ghci
λ main
"<interactive>: stack ghci: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
Started"
{-# LANGUAGE LambdaCase #-}
module Main where


import System.IO (stdin, hSetEcho, hReady, stdout)
import GHC.IO.Handle
import Control.Monad (when)
import System.Process
import Control.Monad.STM
import Control.Concurrent.STM.TMVar
import Control.Concurrent
import Control.Monad


getKey :: IO [Char]
getKey = reverse <$> getKey' ""
  where getKey' chars = do
          char <- getChar
          more <- hReady stdin
          (if more then getKey' else return) (char:chars)

type Commands = TMVar [String]

ghci :: Commands -> IO ()
ghci cmds = createProcess ((proc "stack ghci" [])) {std_in=CreatePipe} >>= \case
    (Just pin, Nothing, Nothing, ph) -> processCommandsLoop cmds pin
    _ -> error "Something went wrong"

processCommandsLoop :: Commands -> Handle ->  IO ()
processCommandsLoop cmds input = do
  x <- atomically $ takeTMVar cmds
  forM x (\x' -> do
    print "-- ## Sending command to process:"
    print x'
    hPutStr input (x' ++ "\n")
    hFlush input
    )
  hFlush stdout
  processCommandsLoop cmds input

mainLoop :: TMVar [String] -> IO ()
mainLoop commands = do
  key <- getKey
  when (key /= "\ESC") $ do
    case key of
      "i" -> do
        putStrLn "-- ## Initializing!"
        atomically $ putTMVar commands (
          [
            ":l Tidal"
          , "main"
          ])
      "r" -> putStrLn "-- ## Reloading!"
      "t" -> do
        putStrLn "-- ## Testing!"
        atomically $ putTMVar commands ([":t head", ":t tail"])
      "h" -> putStrLn "-- ## Hushing!"
      "d" -> do
        putStrLn "-- ## Debug!"
        (atomically $ readTMVar commands) >>= print
      _        -> return ()
  mainLoop commands

main :: IO ()
main = do
  hSetBuffering stdout NoBuffering
  hSetBuffering stdin NoBuffering
  cmds <- newEmptyTMVarIO
  ghciThread <- forkIO $ ghci cmds
  print "Started"
  hSetEcho stdin False
  mainLoop cmds

It is on line 25. A complete functional project can be found here: https://github.com/chrissound/InteractiveTidalGhci (this would be with ghci - so line 25 would have to be changed).

Possibly related:
leksah/leksah#472
#2489

@snoyberg
Copy link
Contributor

You're calling proc "stack ghci" [], which means "there's an executable called stack ghci, and I'd like to pass it no arguments." You probably meant proc "stack" ["ghci"].

@chrissound
Copy link
Author

Yes that fixed it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants