CGI 的標準入出力


  目次

AN HTTPD で動かしてみます



  スタンダード




  

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{

	char buffer[1024];
	char *ptr,*get;

	ptr = getenv( "REQUEST_METHOD" );

	// HTTP ヘッダ出力
	printf( "Content-Type: text/html; Charset=shift_jis\n" );
	printf( "\n\n" );

	// 本文出力
	printf( "%s<br>\n", ptr );

	// GET
	if ( strcmpi( ptr, "GET" ) == 0 ) {
		get = getenv( "QUERY_STRING" );
		printf( "QUERY_STRING : %s<br>\n", get );
	}

	// POST
	if ( strcmpi( ptr, "POST" ) == 0 ) {
		while( fgets( buffer,1024,stdin ) != NULL ) {
			printf("%s", buffer );
		}
	}

	return 0;
}
  

  C++ with lightbox.lib

  

Set CL6="C:\Program Files\Microsoft Visual Studio\VC98\Bin\cl.exe"
Set LINK6="C:\Program Files\Microsoft Visual Studio\VC98\Bin\link.exe"
Set INC6="C:\Program Files\Microsoft Visual Studio\VC98\Include"
Set INCA="C:\Program Files\Microsoft Visual Studio\VC98\ATL\Include"
Set LIB6="C:\Program Files\Microsoft Visual Studio\VC98\Lib"
Set LIBS1=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
Set LIBS2=shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
%CL6% cgi_01.cpp /c /I%INC6% /I%INCA%
%LINK6% /LIBPATH:%LIB6% cgi_01.obj %LIBS1% %LIBS2%
  

  

#include "lightbox.h"

int main(int argc, char* argv[])
{

	LboxString Method,QueryString,Buffer;

	Method.Resize( 80 );
	GetEnvironmentVariable(
		"REQUEST_METHOD", Method.szLboxString, Method.nLboxString );

	// HTTP ヘッダ出力
	printf( "Content-Type: text/html; Charset=shift_jis\n" );
	printf( "\n\n" );

	// 本文出力
	printf( "%s<br>\n", Method.szLboxString );

	// GET
	if ( Method == "GET" ) {
		QueryString.Resize( 2048 );
		GetEnvironmentVariable(
			"QUERY_STRING",
			QueryString.szLboxString,
			QueryString.nLboxString );
		printf( "QUERY_STRING : %s<br>\n", QueryString.szLboxString );
	}

	// POST
	if ( Method == "POST" ) {
		Buffer.Resize( 1024 );
		while( fgets( Buffer.szLboxString,1024,stdin ) != NULL ) {
			printf("%s", Buffer.szLboxString );
		}
	}

	return 0;
}
  

  Java

AN HTTP Server で、.class を java_wrap.exe で登録

java_wrap.cpp
  

#include <stdio.h>
#include <process.h>
#include <string.h>

int main(int argc, char* argv[])
{
	char *ptr;
	char buff[128];
	char command[128];

	ptr = argv[1];
	strcpy( buff, argv[1] );

	int i,len;
	len = strlen( buff );
	for( i = len-1; i >=0 ; i-- ) {
		if ( buff[i] == '.' ) {
			buff[i] = 0x00;
		}
		if ( buff[i] == '\\' ) {
			ptr = buff+i+1;
			break;
		}
	}

	strcpy( command, "java -cp . " );
	strcat( command, ptr );

	system( command );

	return 0;
}
  

  

import java.io.*;

public class lang {
	public static void main(String[] args) {

		try {
			doFunction();
		}
		catch ( Exception e ) {
		}

	}

	public static void doFunction() throws IOException {

		String strMethod = System.getenv("REQUEST_METHOD");

		System.out.println( "Content-Type: text/html; Charset=shift_jis" );
		System.out.println( "" );

		System.out.println( strMethod + "<br>" );

		if ( strMethod.equals( "GET" ) ) {
			String strQueryString = 
				System.getenv( "QUERY_STRING" );
			System.out.println( strQueryString );
		}

		if ( strMethod.equals( "POST" ) ) {
			BufferedReader read =
			   new BufferedReader(new InputStreamReader(System.in));

			String line = null;
			while( (line = read.readLine()) != null ) {
				System.out.println( line );
			}
		}

	}
}
  

  WSH ( VBScript )

AN HTTP Server で、.vbs を cscript.exe //Nologo で登録



  

' オブジェクト作成
Set WshShell = CreateObject("WScript.Shell")

' 環境変数を取得
Set WshSysEnv = WshShell.Environment("PROCESS")
strMethod = UCase( WshSysEnv("REQUEST_METHOD") )

WScript.Echo "Content-Type: text/html; Charset=shift_jis"
WScript.Echo ""

WScript.Echo strMethod & "<br>"

if strMethod = "GET"  then
	strQueryString = WshSysEnv("QUERY_STRING")
	WScript.Echo strQueryString
end if

if strMethod = "POST"  then
	WScript.Echo Wscript.StdIn.ReadAll
end if
  

  VB + Framework

  

Imports System.Environment
Imports System.IO

Module MyModule

' ********************************************************
' * 実行
' ********************************************************
Sub Main()

	' PATH 環境変数取得
	Dim strMethod as String = GetEnvironmentVariable( "REQUEST_METHOD" )

	Console.WriteLine("Content-Type: text/html; Charset=shift_jis")
	Console.WriteLine("")

	Console.WriteLine("{0}<br>", strMethod )

	if strMethod = "GET"  then
		Dim strQueryString as String = GetEnvironmentVariable( "QUERY_STRING" )
		Console.WriteLine(strQueryString)
	end if

	if strMethod = "POST"  then
		Dim line As String
		line = Console.ReadLine()
		Do While Not line Is Nothing
			Console.WriteLine(line)
			line = Console.ReadLine()
		Loop
	end if

End Sub

End Module
  

  C#

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace WebApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //string formtype = "GET";
            string formtype = "POST";

            string[] param = {""};

            // ******************************
            // Console.WriteLine を UTF8 で
            // ******************************
            Console.OutputEncoding = Encoding.UTF8;

            // ******************************
            // メソッド
            // ******************************
            string method = Environment.GetEnvironmentVariable("REQUEST_METHOD");
            // ******************************
            // QUERY_STRING
            // ******************************
            string query_string = System.Environment.GetEnvironmentVariable("QUERY_STRING");

            // ******************************
            // HTTP ヘッダ
            // PHP の session_cache_limiter
            // ******************************
            Console.WriteLine("Content-Type: text/html; charset=utf-8");
            Console.WriteLine("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
            Console.WriteLine("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
            Console.WriteLine("Pragma: no-cache");
            Console.WriteLine();

            string message = "<div>こんにちは世界</div>";

            // ******************************
            // HTML
            // ******************************
            string html = @"<!DOCTYPE html>
<html>
<head>
</head>
<body>
#{message}
<form method='#{formtype}'>
<p>氏名 : <input type='text' name='field1' value='#{field1}'></p>
<p>フリガナ : <input type='text' name='field2' value='#{field2}'></p>
<p>送信 : <input type='submit' name='send' value='送信'></p>
</form>
</body>
</html>";
            html = html.Replace("#{formtype}", formtype);

            // ******************************
            // GET
            // ******************************
            if (method == "GET")
            {
                param = query_string.Split('&');
            }

            // ******************************
            // POST
            // ******************************
            if (method == "POST")
            {
                string line = null;
                line = Console.ReadLine();
                param = line.Split('&');
            }

            foreach (string set in param)
            {
                string[] key_value = set.Split('=');
                if (key_value[0] == "field1")
                {
                    // System.Web を参照して using System.Web;
                    key_value[1] = HttpUtility.UrlDecode(key_value[1]);
                    html = html.Replace("#{field1}", key_value[1]);
                }
                if (key_value[0] == "field2")
                {
                    key_value[1] = HttpUtility.UrlDecode(key_value[1]);
                    html = html.Replace("#{field2}", key_value[1]);
                }
            }


            html = html.Replace("#{field1}", "");
            html = html.Replace("#{field2}", "");


            // #{} は Ruby の真似
            html = html.Replace("#{message}", message);

            Console.WriteLine(html);


        }
    }
}
  

  Jscript + Framework

  

import System;
import System.IO;


// PATH 環境変数取得
var strMethod : String = 
	Environment.GetEnvironmentVariable( "REQUEST_METHOD" );

// HTTP ヘッダ
Console.WriteLine("Content-Type: text/html; Charset=shift_jis");
Console.WriteLine("");

Console.WriteLine("{0}<br>", strMethod );

if ( strMethod == "GET" ) {
	var strQueryString : String = 
		Environment.GetEnvironmentVariable( "QUERY_STRING" );
	Console.WriteLine(strQueryString);
}

if ( strMethod == "POST" ) {
	var line : String = null;
	line = Console.ReadLine();
	while( line != null ) {
		Console.WriteLine(line);
		line = Console.ReadLine();
	}
}
  

  WSH ( Jscript )

AN HTTP Server で、.js を cscript.exe //Nologo で登録

  

// オブジェクト作成
var WshShell = new ActiveXObject("WScript.Shell");

// システム環境変数を取得
var WshSysEnv = WshShell.Environment("PROCESS");
var strMethod = WshSysEnv("REQUEST_METHOD");

WScript.Echo( "Content-Type: text/html; Charset=shift_jis" );
WScript.Echo( "" );

WScript.Echo( strMethod + "<br>" )

if ( strMethod == "GET" ) {
	strQueryString = WshSysEnv("QUERY_STRING");
	WScript.Echo( strQueryString );
}

if ( strMethod == "POST" ) {
	WScript.Echo( WScript.StdIn.ReadAll() );
}
  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[PROc]
claudebot
24/03/29 09:10:44
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube