将DOS程序返回信息及时地输出到 VCL 控件上?(100分)

  • 主题发起人 主题发起人 apworkroom
  • 开始时间 开始时间
A

apworkroom

Unregistered / Unconfirmed
GUEST, unregistred user!
将DOS程序返回信息及时地输出到 VCL 控件上?<br>要求能在 95、98 和 NT 环境下都正常运行。<br>找了好久了!<br>希望有demo<br>apdong@163.com<br>
 
注意:要求是能在VCL控件(比如memo)中获得Oracle的Exp程序的执行输出内容。<br>我找到的答案都是只能获得象ping等程序的输出,对exp都无能为力!比如:<br>&nbsp; &nbsp;EXP80 userid=scott/tiger File=Bak.dmp<br>这条命令在dos下执行时显示的信息。<br><br>我使用的是oracle8.0.5+delphi6<br>
 
我连ping的都没找到!! 我要得到nbtstat的结果!!
 
来自:xiaomaoxia, 时间:2003-6-16 21:05:00, ID:1957081<br>我连ping的都没找到!! 我要得到nbtstat的结果!! &nbsp;<br><br>我得到ping的输出的代码如下:摘自 Aiirii &nbsp;的答案<br>procedure TForm1.btnRunClick(Sender: TObject);<br>var<br>&nbsp;hReadPipe,hWritePipe:THandle;<br>&nbsp;si:STARTUPINFO;<br>&nbsp;lsa:SECURITY_ATTRIBUTES;<br>&nbsp;pi:PROCESS_INFORMATION;<br>&nbsp;mDosScreen:String;<br>&nbsp;cchReadBuffer:DWORD;<br>&nbsp;ph:PChar;<br>&nbsp;fname:PChar;<br>&nbsp;i,j:integer;<br>begin<br>&nbsp;fname:=allocmem(255);<br>&nbsp;ph:=AllocMem(5000);<br>&nbsp;lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);<br>&nbsp;lsa.lpSecurityDescriptor :=nil;<br>&nbsp;lsa.bInheritHandle :=True;<br><br>&nbsp;if CreatePipe(hReadPipe,hWritePipe,@lsa,0)=false then<br>&nbsp;begin<br>&nbsp; &nbsp;ShowMessage('Can not create pipe!');<br>&nbsp; &nbsp;exit;<br>&nbsp;end;<br>&nbsp;fillchar(si,sizeof(STARTUPINFO),0);<br>&nbsp;si.cb :=sizeof(STARTUPINFO);<br>&nbsp;si.dwFlags :=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);<br>&nbsp;si.wShowWindow :=SW_HIDE;<br>&nbsp;si.hStdOutput :=hWritePipe;<br>&nbsp;StrPCopy(fname,'CMD.EXE /c dir/w');<br><br>&nbsp;if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False &nbsp;the<br>n<br>&nbsp;begin<br>&nbsp; &nbsp;ShowMessage('can not create process');<br>&nbsp; &nbsp;FreeMem(ph);<br>&nbsp; &nbsp;FreeMem(fname);<br>&nbsp; &nbsp;Exit;<br>&nbsp;end;<br><br>&nbsp;while(true) do<br>&nbsp;begin<br>&nbsp; &nbsp;if not PeekNamedPipe(hReadPipe,ph,1,@cchReadBuffer,nil,nil) then break;<br>&nbsp; &nbsp;if cchReadBuffer&lt;&gt;0 then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;if ReadFile(hReadPipe,ph^,4096,cchReadBuffer,nil)=false then break;<br>&nbsp; &nbsp; &nbsp;ph[cchReadbuffer]:=chr(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Memo1.Lines.Add(ph);<br>&nbsp; &nbsp;end<br>&nbsp; &nbsp;else if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then break;<br>&nbsp; &nbsp;Sleep(100);<br>&nbsp;end;<br><br>&nbsp;ph[cchReadBuffer]:=chr(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Memo1.Lines.Add(ph);<br>&nbsp;CloseHandle(hReadPipe);<br>&nbsp;CloseHandle(pi.hThread);<br>&nbsp;CloseHandle(pi.hProcess);<br>&nbsp;CloseHandle(hWritePipe);<br>&nbsp;FreeMem(ph);<br>&nbsp;FreeMem(fname);<br>end; &nbsp;<br>
 
怎么没人理我?<br>怎么没人理我?<br>怎么没人理我?<br>!!!!!!
 
写一个控制台程序就可以了
 
给个例子吧!<br>给个例子吧!<br>给个例子吧!<br>
 
我不是高手,所有我有个笨办法,别笑哦,否则我就不说了。<br><br>用管道命令将结果输出到一个文件中,然后再把文件内容调到MEMO中去。<br><br>不知道可不可以。
 
算了,没高手关注!<br>结贴!
 
多人接受答案了。
 
ping 127.0.0.1 &gt;c:/tt.txt<br>Memo1.Lines.LoadFromFile('c:/tt.txt');<br>
 
tree &gt;c:/1.txt<br>memo1.lines.loadfromfile('c:/1.txt')
 
嘿嘿,鼎鼎的张大虾用的方法原来和我的一样哦。
 
后退
顶部