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?

4
  • 2
    You know about System.Process, right? Specifically callProcess "python" []. Commented Nov 8, 2016 at 21:13
  • 2
    and in a turtle context: view $ liftIO $ callProcess "python" [] Commented Nov 8, 2016 at 21:34
  • That is exactly what I was looking for. Thanks @ja Commented Nov 9, 2016 at 23:54
  • Or even better in Turtle (if you don't want to see the () being printed out after the interactive process exits): sh $ liftIO $ callProcess "python" [] Commented Jan 16, 2020 at 7:19

2 Answers 2

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" []
Sign up to request clarification or add additional context in comments.

2 Comments

Why not main = callProcess "python" [] directly?
You could do that. But my usecase was to execute it withing the context of larger script which already contains Turtle's Shell actions.
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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.