9.3.5 UOCコーディング例
後処理UOCのコーディング例を次に示します。
- 〈この項の構成〉
(1) Windowsアプリケーションの場合
この例では,変換で使用したスプールデータを使用して,再度ジョブコメントで指定した環境設定名で変換します。
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
#include <string.h>
#define MSMAIN "C:\\Program Files\\HITACHI\\PDE for Open\\BIN\\msmain.exe"
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
/*local areas*********************************************************/
char *infile; /* input spool file name */
char *outfile; /* output spool file name */
char *cmtbuf; /* JCL comment area buffer */
char cmtarea[65]; /* JCL comment area */
int i; /* work loop counter */
int j; /* work counter */
int cmdL; /* command line length */
DWORD ExitCode; /* exit code */
PROCESS_INFORMATION procInfo; /* process information */
STARTUPINFO stInfo; /* process startup information */
BYTE CallCmdLine[512]; /* command line for call proc*/
DWORD Event; /* process wait event code */
DWORD rc; /* win32 last error code */
/*process start*******************************************************/
cmdL = lstrlen(lpCmdLine);
infile = outfile = cmtbuf = NULL;
memset(cmtarea, '\0', sizeof(cmtarea));
/* input file name get */
for (i = 0; i < cmdL; i++)
{
if ('"' == lpCmdLine[i])
{
if (NULL == infile)
infile = &lpCmdLine[i + 1];
else
{
lpCmdLine[i] = '\0';
break;
}
}
}
/* output file name get */
for ( ; i < cmdL; i++)
{
if ('"' == lpCmdLine[i])
{
if (NULL == outfile)
outfile = &lpCmdLine[i + 1];
else
{
lpCmdLine[i] = '\0';
break;
}
}
}
/* JCL comment area get */
for ( ; i < cmdL; i++)
{
if ('\\' == lpCmdLine[i])
{
i++;
}
else if ('"' == lpCmdLine[i] )
{
if (NULL == cmtbuf)
cmtbuf = &lpCmdLine[i + 1];
else
{
lpCmdLine[i] = '\0';
break;
}
}
}
for (i = 0, j = 0; i < lstrlen(cmtbuf); i++) {
if ('\\' == cmtbuf[i])
{
i++;
}
cmtarea[j++] = cmtbuf[i];
}
if (!*cmtarea)
{
ExitProcess(1);
}
/* UOC Start */
/* コマンドライン組み立て: msmain.exe 入力ファイル名, 環境設定名*/
sprintf(CallCmdLine, "\"%s\" %s,%s", MSMAIN, infile, cmtarea);
memset(&stInfo, '\0', sizeof(STARTUPINFO));
stInfo.cb = sizeof(STARTUPINFO);
if (!CreateProcess(MSMAIN, CallCmdLine, NULL, NULL,
FALSE, CREATE_NEW_PROCESS_GROUP, NULL,
NULL, &stInfo, &procInfo))
{
rc = GetLastError();
ExitProcess(rc);
}
GetExitCodeProcess(procInfo.hProcess, &ExitCode);
while (ExitCode == STILL_ACTIVE)
{
Event = WaitForSingleObject(procInfo.hProcess, INFINITE);
if (WAIT_TIMEOUT != Event &&
WAIT_ABANDONED != Event)
{
GetExitCodeProcess(procInfo.hProcess, &ExitCode);
}
}
CloseHandle(procInfo.hProcess);
if (ExitCode == 0)
{
ExitProcess(1);
}
else if (ExitCode != 1)
{
ExitProcess(ExitCode);
}
ExitProcess(1);
}
(2) スクリプトの場合
この例では,変換で使用したスプールデータを使用して「C:\Hitachi\PDESample.txt」に変換時刻(環境変数_PDE_TIME)を出力し,戻り値0で終了します。
-
batファイルの場合
@echo off
rem 出力されるファイル名を環境変数にセット
set OutputFileName=C:\\Hitachi\\PDESample.txt
rem 環境変数 _PDE_TIMEをファイルに出力
echo %_PDE_TIME% >> %OutputFileName%
rem 戻り値を返す
exit 0-
VBScriptの場合
Option Explicit
'ファイルオブジェクトの生成
Dim FileObj
Dim FilePt
set FileObj = CreateObject("Scripting.FileSystemObject")
set FilePt = FileObj.CreateTextFile("C:\\Hitachi\\PDESample.txt") '出力ファイル名
'環境変数 _PDE_TIMEをファイルに出力
Dim WshObj
set WshObj = CreateObject("WScript.Shell")
FilePt.Write("TIME : ")
Dim Env
set Env = WshObj.Environment("PROCESS")
FilePt.WriteLine(Env("_PDE_TIME"))
'後処理
FilePt.Close()
set FilePt = Nothing
set FileObj = Nothing
'戻り値を返す
WScript.quit(0)-
JScriptの場合
//ファイルオブジェクトの生成
var FileObj;
var FilePt;
FileObj = new ActiveXObject("Scripting.FileSystemObject");
FilePt = FileObj.OpenTextFile("C:\\Hitachi\\PDESample.txt", 2, -2);
//環境変数 _PDE_HOSTIDをファイルに出力
var WshObj = new ActiveXObject("WScript.Shell");
FilePt.Write("TIME : ");
var Env = WshObj.Environment("PROCESS");
FilePt.WriteLine(Env("_PDE_TIME"));
//後処理
FilePt.Close();
FilePt = null;
FileObj = null;
//戻り値を返す
WScript.quit(0);