3

I am trying to run an interactive command with haskell turtle library like this:

#!/usr/bin/env stack
-- stack --install-ghc runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import Turtle
main = procs "python" [] empty

(I also tried shells function but it does not work either.) When I run it nothing hapens:

$ ./turtleTest.hs
$

But if I change "python" command to "ls" it works.

How can I run an interactive command like python repl with turtle library?

yilmazhuseyin
  • 6,442
  • 4
  • 34
  • 38

2 Answers2

2

Here's a complete working example extracted from comments. Tu run interactive process via Turtle you can do something like this:

#!/usr/bin/env stack
-- stack script --resolver lts-14.20 --package turtle --package process
{-# LANGUAGE OverloadedStrings #-}

import System.Process (callProcess)
import Turtle (sh, liftIO)

main :: IO ()
main = sh $ liftIO $ callProcess "python" []
Jan Hrcek
  • 626
  • 11
  • 24
  • Why not `main = callProcess "python" []` directly? – Leo Jul 25 '21 at 12:28
  • 1
    You could do that. But my usecase was to execute it withing the context of larger script which already contains Turtle's Shell actions. – Jan Hrcek Jul 27 '21 at 12:48
0
{-# LANGUAGE OverloadedStrings #-}

import Turtle.Prelude (proc, procs, shell, shells)

main :: IO ()
main = do
  procs "ls" [] mempty         --(without ExitCode)
  procs "ls" ["-la"] mempty    --(without ExitCode)
  proc "pwd" [] mempty         --(with ExitCode)
  proc "ls" ["-la"] mempty     --(with ExitCode)

  shells "ls -la" mempty       --(without ExitCode)
  shell "pwd" mempty           --(with ExitCode)
  shell "ls -la" mempty        --(with ExitCode)
Chris
  • 56
  • 4