我正在用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
不行。
有没有可能以这样的方式做到这一点?
- 没有进口的普通,或
- 可以在拥抱中导入
尝试import System.Environment (getEnv)
.