C
catfox
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure MyRun_pipe(cmd: String; var m: TMemo);<br>var<br> hReadPipe,hWritePipe:THandle;<br> si:STARTUPINFO;<br> lsa:SECURITY_ATTRIBUTES;<br> piROCESS_INFORMATION;<br> mDosScreen:String;<br> cchReadBufferWORD;<br> phChar;<br> fnameChar;<br> i,j:integer;<br>begin<br> try<br> Screen.Cursor := crSQLWait;<br> fname:=allocmem(255);<br> ph:=AllocMem(5000);<br> lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);<br> lsa.lpSecurityDescriptor :=nil;<br> lsa.bInheritHandle :=True;<br><br> if CreatePipe(hReadPipe,hWritePipe,@lsa,0)=false then<br> begin<br> ShowMessage('Can not create pipe!');<br> exit;<br> end;<br> fillchar(si,sizeof(STARTUPINFO),0);<br> si.cb :=sizeof(STARTUPINFO);<br> si.dwFlags :=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);<br> si.wShowWindow :=SW_HIDE;<br> si.hStdOutput :=hWritePipe;<br> StrPCopy(fname,cmd);<br> if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False then<br> begin<br> ShowMessage('can not create process');<br> FreeMem(ph);<br> FreeMem(fname);<br> Exit;<br> end;<br><br> while(true) do<br> begin<br> // 查询管道缓冲区内可读的字节数<br> if not PeekNamedPipe(hReadPipe,ph,1,@cchReadBuffer,nil,nil) then break;<br> if cchReadBuffer<>0 then<br> begin<br> if ReadFile(hReadPipe,ph^,4096,cchReadBuffer,nil)=false then break;<br> ph[cchReadbuffer]:=chr(0);<br> m.Lines.Add(ph);<br> end<br> else if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then break;<br> Sleep(100);<br> end;<br><br> ph[cchReadBuffer]:=chr(0);<br> m.Lines.Add(ph);<br> CloseHandle(hReadPipe);<br> CloseHandle(pi.hThread);<br> CloseHandle(pi.hProcess);<br> CloseHandle(hWritePipe);<br> FreeMem(ph);<br> FreeMem(fname);<br> finally<br> Screen.Cursor := crDefault;<br> end;<br>end;<br><br>参考的帖子在<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=638463<br><br>但想把这个代码应用到oracle的导出工具exp,就是没有输出结果,但exp是运行了的,而且也可以产生log日志文件,不知道为什么在管道中没有输出信息???<br>(我是要实时输出,不能用exp完成后再读取log文件的方法)<br><br>有oracle的exp工具的大富翁帮忙看看是什么问题, 谢了