在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
--我必须把脚本的完整路径,它的工作
结果这个问题非常广泛。请给出一些实际代码和问题的描述