使用haskell turtle库运行交互命令



我正在尝试使用haskell turtle库运行一个交互式命令:

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

(我也尝试过shell功能,但它也不起作用。)当我运行它时,什么也没发生:

$ ./turtleTest.hs
$

但是如果我将"python"命令改为"ls",它就可以工作了。

我如何运行一个交互式命令,如python repl与龟库?

下面是一个从注释中提取的完整的工作示例。要通过Turtle运行交互式进程,您可以这样做:

#!/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" []
{-# 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)

最新更新