Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Haskell中加载Shell脚本文件以访问其函数_Haskell - Fatal编程技术网

在Haskell中加载Shell脚本文件以访问其函数

在Haskell中加载Shell脚本文件以访问其函数,haskell,Haskell,我有一个名为/path/to/shell_script.sh的shell脚本文件,其中包含一个函数定义shell_function(){…} 我希望能够在Haskell中使用ExitCode shell_函数[]执行一些操作,如readProcessWithExitCode shell\u函数,以最终获得IO(字符串) 如何执行此操作?如果您有类似的shell脚本 #!/bin/bash foo() { echo "foo" } 您可以使用process package中的函数来获取

我有一个名为
/path/to/shell_script.sh
的shell脚本文件,其中包含一个函数定义
shell_function(){…}

我希望能够在Haskell中使用ExitCode shell_函数[]执行一些操作,如
readProcessWithExitCode shell\u函数
,以最终获得
IO(字符串)


如何执行此操作?

如果您有类似的shell脚本

#!/bin/bash

foo() {
    echo "foo"
}
您可以使用process package中的函数来获取脚本的源代码,并一次性执行该函数,如下所示:

module Main where

import System.Process

main :: IO ()
main = do
    -- I had to put the full path of the script for it to work
    result <- readCreateProcess ((shell ". /tmp/foo.sh && foo")) ""
    print result
modulemain其中
导入系统。进程
main::IO()
main=do
--我必须把脚本的完整路径,它的工作

结果这个问题非常广泛。请给出一些实际代码和问题的描述