如果获得DOS程序输出的字符? ( 积分: 0 )

  • 主题发起人 主题发起人 winni
  • 开始时间 开始时间
W

winni

Unregistered / Unconfirmed
GUEST, unregistred user!
如果获得DOS程序输出的字符?
 
如果获得DOS程序输出的字符?
 
1。写一个驱动级的程序拦截中断
2。如果是你自己来启动这个程序的话,自己写一个TSR来定时读取$A800:0开始的字符状态显存(DOS下)
 
兄弟,0分也问!还是告诉你吧。

放一个memo和button在form中

procedure RunDosInMemo(DosApp:String;Amemo:Tmemo);
const
ReadBuffer = 2400;
var
Security : TSecurityAttributes;
ReadPipe,WritePipe : Thandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : Dword;
Apprunning : Dword;
begin
With Security do begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;

if Createpipe (ReadPipe, WritePipe, @Security, 0) then begin
Buffer := AllocMem(ReadBuffer + 1);
FillChar(Start,Sizeof(Start),#0);
start.cb := SizeOf(start);
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;
if CreateProcess(nil,Pchar(DosApp),@Security,@Security,true,NORMAL_PRIORITY_CLASS,nil,nil,start,ProcessInfo) then begin
repeat
Apprunning := WaitForSingleObject(ProcessInfo.hProcess,100);
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT);

Repeat
BytesRead := 0;
ReadFile(ReadPipe,Buffer[0],ReadBuffer,BytesRead,nil);
Buffer[BytesRead]:= #0;
OemToAnsi(Buffer,Buffer);
Amemo.Text := Amemo.text + String(Buffer);
until (BytesRead < ReadBuffer);
end;

FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ReadPipe);
CloseHandle(WritePipe);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RunDosInMemo('ping 192.168.1.1',Memo1);
end;
 
接受答案了.
 
后退
顶部