Escript是一個使用Erlang編寫的簡單腳本執行工具。這是一個很好的工具,但幫助手冊中大多是講述UNIX下的使用方法,如果我們想在Windows操作系統下運行腳本,可以這樣來使用:
C:\temp>escript factorial.escript 5 escript: Failed to open file: C:\temp\escript.escript
糟糕!出現異常,先看下escript的來源。在Windows下需要用程序名稱來調用它(在我們的escript示例中):如果不添加exe作爲escript的後綴,那麼會自動添加escript後綴來試圖運行,所以會提示escript.escript不存在。顯然這是一個錯誤,要解決它,可以添加exe後綴來執行我們的命令:
C:\temp>escript.exe factorial.escript 5 factorial 5 = 120
另一個需要注意的地方是:第一行不能有erlang代碼(這個地方是留給UNIX的#內容的)。如果你試圖運行下面的腳本:
main(Args) -> print_args(Args). print_args([]) -> ok; print_args([FirstArg | Rest]) -> io:format("~s~n", [FirstArg]), print_args(Rest).
會得到這樣的結果
C:\temp>escript.exe x.escript Hello World x.escript:2: syntax error before: '.' escript: There were compilation errors.
你必須在main前面增加一行再運行。