在没有包的情况下,在带有哈斯克尔/拥抱的 CGI 中获取环境变量



我正在用Haskell编写一个cgi脚本。我只能使用拥抱/跑拥抱。

#!/opt/local/bin/runhugs
module Main where
main = do
        putStrLn ("content-type: text/plainn")
        putStrLn ("Hello, Server!")

目前为止,一切都好。但是现在我想获取服务器的环境变量。例如,"SCRIPT_NAME"环境变量。

通过bash,我可以做到:

#!/bin/bash
echo "content-type: text/plain;"
echo ""
echo $SCRIPT_NAME

结果:/path/to/script.cgi浏览器窗口中。

对于哈斯克尔,我发现了类似的东西:script <- getEnv "SCRIPT_NAME",但

#!/opt/local/bin/runhugs
module Main where
main = do
        putStrLn ("content-type: text/plainn")
        scriptname <- getEnv "SCRIPT_NAME"
        putStrLn scriptname

不行。

有没有可能以这样的方式做到这一点?

  1. 没有进口的普通,或
  2. 可以在拥抱中导入

尝试import System.Environment (getEnv) .

最新更新