LoginSignup
4
4

More than 5 years have passed since last update.

D言語でCGI

Last updated at Posted at 2012-12-12

ひょっとしなくても居ないと好いのですが、CGI (Common Gateway Interface) は、PHPやPerlで書くものだと思っている人は悔い改めよ。このものたちはただ悔い改めて終わるものではない。唯一神Dが業火に投げ込むものである。
D言語

CGIはPerl等で書く事が多いのは確かですが、標準入力と標準出力をもつ実行ファイルに過ぎませんので、D言語でCGIを使う難易度は、低いものです。
vibe.dと云う便利なWebフレームワークも出来ましたが、素人である私のレベルにあわせて、古のCGIを使いましょう。

ne.d
import std.stdio;

void main() {
  printf(`content-type: text/html

<!DOCTYPE HTML>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>ももんが</title>
</head>
<body>
  ももんが
</body>
</html>`);
}

これをdmd ne.dとし、できたne.exeを、ne.cgiの名でCGIのディレクトリへ置けば、完成です。

私の環境ではvibe.dが動かなかったのですが、余りに素人過ぎて、原因を探り当てる迄いきませんでした。ついでにstd.processやstd.file等もimport出来ないのですが……。

4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4