使用haskell turtle库运行交互式命令

kmpatx3s  于 2022-11-14  发布在  其他
关注(0)|答案(2)|浏览(174)

我试图运行一个交互式命令与 haskell 海龟库这样:

#!/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库?

doinxwow

doinxwow1#

下面是一个从评论中提取的完整的工作示例。通过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" []
ffscu2ro

ffscu2ro2#

{-# 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)

相关问题