developer's diary

最近はc#のエントリが多いです

OpenCOBOLとapache2 (Ubuntu10.04でCGIを試す。)

参考:COBOL‚ÅCGI

必要なモジュールをインストール

sudo aptitude install open-cobol gcc apache2

hello.cob

        IDENTIFICATION  DIVISION.
        PROGRAM-ID.     HELLOCGI.

        DATA            DIVISION.
        WORKING-STORAGE SECTION.

        PROCEDURE       DIVISION.
        HTML-MAIN       SECTION.
            DISPLAY 'Content-type: text/html'.
            DISPLAY ''.
            DISPLAY '<html>'.
            DISPLAY '<head>'.
            DISPLAY '<title>COBOLCGI</title>'.
            DISPLAY '</head>'.
            DISPLAY '<body>'.
            DISPLAY 'HELLO WORLD!!'.
            DISPLAY '</body>'.
            DISPLAY '</heml>'.
        HTML-FIN.
            STOP RUN.

コンパイルを行う

cobc -x hello.cob

apacheのcgiのルートにコピー(拡張子も変更)

 sudo cp hello /usr/lib/cgi-bin/hello.cgi

http://apache2をインストールしたサーバ/cgi-bin/hello.cgi
にアクセス。

f:id:mitsugi-bb:20100803085350p:image

動いたので本日のCOBOL学習は終了。