아래 임프님께서 해논게 있는데... 여튼, 전 이런 저런 방법 다 동원해도 안될때가
있더군요. ( 아마도 퍼스널 웹서버가 DLL파일을 바꿔서 일어난듯... ) 그래서
ShellExecete를 사용해서 만들어 봤는데 비교적 잘 동작하구요. 단, FileExists로
파일의 존재 여부를 조사하고 난 후에도 조금의 Dealy( 약 0.5 )를 주셔야 합니다.
파일의 내용이 다 써지지 않는 경우가 생기더군요. ^^;;
허접한 쏘쓰 올려놔서 지송여... 잘 고쳐쓰면 쓸만한듯... ^^;;
function DosExecute( psCommand, psOutput, psInput : String; pbAutoClose : Boolean ) : Boolean;
var
lbRetry,
lbDoDefaultRead : Boolean;
lwHInst : DWORD;
begin
Result := FALSE;
// Command line을 완성한다
if pbAutoClose = TRUE then
psCommand := '/c ' + psCommand;
if psInput <> '' then
psCommand := psCommand + ' < ' + psInput;
if psOutput <> '' then
psCommand := psCommand + ' > ' + psOutput;
// DOS 프로그램 실행
lwHInst := ShellExecute( 0, 'open', 'Command.com', PChar( psCommand ), nil, SW_HIDE );
if lwHInst < 32 then
EXIT;
// 데이타 파일이 있는지 확인하고 File에서 데이타를 읽는다
if psOutput <> '' then
begin
DoDelay; // 지연함수... 만들어 넣으세염.. ^^a...
Result := FileExists( psOutput );
if Result = FALSE then
begin
lbRetry := FALSE;
if Assigned( FOnOutfileNotFound ) = TRUE then
begin
FOnOutfileNotFound( Self, lbRetry ); // File이 없을때 어케할까 물어보는 함수... 이것도 만들어 넣으세염.. ^^a...
if lbRetry = TRUE then
Result := FileExists( psOutput );
end;
if Result = FALSE then
begin
Application.MessageBox( PChar( 'Output file <' + psOutput + '> file not found' ), '',
MB_ICONEXCLAMATION + MB_OK );
EXIT;
end;
end;
ReadFromFile( psOutput ); // 파일의 내용을 읽는 함수염... 요것도 직접 ^^a;;~~
DeleteFile( psOutput );
Result := TRUE;
end;
end;
호출방법
DosExecute( 'DosPg.exe', 'result.txt', 'password?', TRUE );
|