2011-10-14 52 views

回答

5

有在FPC的SVN主幹的instantfpc: http://svn.freepascal.org/svn/fpc/trunk/utils/instantfpc/

這裏的自述:

instantfpc 
========== 

This tool allows to execute pascal programs as unix scripts. 
A unix script starts with a shebang #! and the program to execute. For example 

#!/usr/bin/env instantfpc 
begin 
    writeln('It works'); 
end. 

If you save the above file as test.pas and set the execute permission 
(chmod a+x) you can execute the script simply with 
./test.pas 


Installation 
============ 

1. Compile instantfpc.lpi using lazarus, lazbuild or via "fpc instantfpc.lpr" 
2. Put the executable "instantfpc" in PATH, for example into 
    /usr/bin/instantfpc or ~/bin/instantfpc. 

That's all. 
Now you can execute pascal programs as scripts. 
+0

謝謝!不幸的是,'fpc'不能用shebang編譯代碼,但我期待將來的版本將它們當作註釋。 – mcandre

+0

是的。 instantfpc在編譯之前移除shebang(instantfptools.pas中的Procedure CommentShebang)。 – mkriheli

+0

這只是一個解決方法 - fpc本身無法處理shebangs,因此您必須爲每個.PAS文件決定是將它作爲腳本運行還是編譯它。 – mcandre

1

您可能有興趣查看名爲ModernPascal.com的項目

- 目標是跨平臺通信和帕斯卡線。

我已經在Mac,Linux和Raspberry Pi上使用它...開始在Windows上測試它...喜歡它!