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.IO;

// ********************************************************
// * 実行
// ********************************************************
public class App
{

	public static void Main() {

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

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

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

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

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

	}

}
  

  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() );
}
  











   SQLの窓    create:2007/06/18  update:2014/09/07   管理者用(要ログイン)





フリーフォントWEBサービス

SQLの窓WEBサービス

SQLの窓フリーソフト

写真素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ