- 论坛徽章:
- 0
|
以前我们用python做的一个演示产品, 以python -m CGIHTTPServer启动服务器后, cgi-bin 目录下的脚本文件根据程序员的喜好, 可以用python, scala开发:
python脚本要加个
#!/usr/bin/python
scala脚本要加个
#!/bin/sh
exec scala "$0"
"$@"
!#
那能否用erlang开发CGI脚本呢? 答案是肯定的,因为eralng提供了escrip可以直接运行erlang代码. 用如下代码测试时, python却报CGI script exit status 0x7f00 ?!
#!/usr/local/bin/escript
-export([main/1]).%% External API
main([]) ->
ensure(),
io:format("~n"),
io:format("welcome to erlang world~n").
%% Internal API
ensure() ->
code:add_patha(filename:dirname(escript:script_name())).
难道是权限问题? 可erlang脚本与同目录下的其它脚本有相同的权限啊! 而且在命令行直接运行erlang脚本却没任何问题。没办法只好研究 CGIHTTPServer.py:
发现运行完os.execve(scriptfile, args, os.environ)
#!/usr/local/bin/escript
-export([main/1]). 后, 你进程得到0x7f00错误码!!! 后经手工运行发现原来是"args" 导致 escript找不到匹配的main函数 !!! 修改如下:
%% External API
main(_) ->
ensure(),
io:format("~n"),
io:format("welcome to erlang world~n").
%% Internal API
ensure() ->
code:add_patha(filename:dirname(escript:script_name())).
修改后程序运行正常。
|
|