运行exp(oracle),把结果输出到win程序的Memo,其他dos程序(ping、cmd)都可以,就是exp不行 (200分)

  • 主题发起人 主题发起人 catfox
  • 开始时间 开始时间
C

catfox

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure MyRun_pipe(cmd: String; var m: TMemo);<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;try<br>&nbsp;Screen.Cursor := crSQLWait;<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);<br>&nbsp;if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False &nbsp;then<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;// 查询管道缓冲区内可读的字节数<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;m.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;m.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>&nbsp;finally<br>&nbsp; Screen.Cursor := crDefault;<br>&nbsp;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工具的大富翁帮忙看看是什么问题, 谢了
 
实在不行就 用&gt;输出到txt 再读吧<br><br>
 
该程序输出字符串没有调用标准的I/O函数,而是其他函数,所以管道功能失效!<br>举个DOS下的例子:<br>mov ah,09h<br>mov al,'a'<br>int 10h<br>和<br>mov ah,09h<br>mov al,'a'<br>int 21h<br>都可以显示字符'a',但是只有后者能输出到管道中!<br><br>
 
exp 。。。 &gt;&gt;d:/a.txt 获取的也是空文本<br><br>那有方法获取这个程序(exp)的屏幕输出吗? &nbsp;thx
 
dir也不行啊<br>telnet也不行<br>time 不行<br>但是把他们放到1.bat中就可以了?????<br><br>
 
帮你提前
 
&nbsp;cmd := Format('%s userid=%s/%s@%s file=%s%s.dmp owner=%s rows=y log=%s%s.log ', [PCmd, PUser, PPassWord, PServer, PPath, dmpName, PUser, PPath, dmpName]);<br>&nbsp; if (WinExec(Pchar(cmd), SW_SHOW)&lt; 31) then showmessage(' WinExec 执行错误!');<br><br><br>这样可以生成。log 看看对你有用没有
 
接受答案了.
 
后退
顶部