毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> 数据库 >> 正文

如何在应用程序中调用db2cmd,实现自动输入命令并读取输出内容

更新时间:2013-7-7:  来源:毕业论文

如何在应用程序中调用db2cmd,实现自动输入命令并读取输出内容

我写了一个windows程序调用db2cmd.exe,通过程序对其输入输出,程序中使用管道函数createpipe+createprocess;
结果弹出db2cmd DOS窗口,但程序发出命令后db2cmd无响应,也无法读取他的输出内容;但是调用其他程序如cmd.exe等可以正常输入输出。
请高手帮忙解释这是什么原因

ReadPipeIn, WritePipeIn,ReadPipeOut, WritePipeOut: THandle;   procedure Createpipe; var   Security: TSecurityAttributes;   start: TStartUpInfo; begin  Security.nlength := SizeOf(TSecurityAttributes);   Security.binherithandle := true;   Security.lpsecuritydescriptor := nil;   {创建一个命名管道用来捕获console程序的输出}  Createpipe(ReadPipeIn, WritePipeIn, @Security, 0);   Createpipe(ReadPipeOut, WritePipeOut, @Security, 0);     FillChar(Start, Sizeof(Start), #0);   CreateProcess(nil,PChar('db2cmd.exe'),@Security,@Security,true,NORMAL_PRIORITY_CLASS,nil,nil,start,ProcessInf);  end; {向console程序输入}procedure WriteToPipe(Pipe: THandle; Value: string); var  len: integer;   BytesWrite: DWord;   Buffer: PChar; begin  len := Length(Value) + 2;   Buffer := PChar(Value + #13#10);   WriteFile(Pipe, Buffer[0], len, BytesWrite, nil); end; {从console程序读取输出}function ReadFromPipe(Pipe: THandle): string; var  Buffer: PChar;   BytesRead: DWord; begin   Result := '';    if GetFileSize(Pipe, nil) = 0 then Exit;    Buffer := AllocMem(ReadBuffer + 1);    repeat       BytesRead := 0;        ReadFile(Pipe, Buffer[0],        ReadBuffer, BytesRead, nil);         if BytesRead > 0 then begin            Buffer[BytesRead] := #0;             OemToAnsi(Buffer, Buffer);             Result := Result+string(Buffer);         end;    until (GetFileSize(Pipe, nil) <= 0);    FreeMem(Buffer); end;

测试了一下,貌似不行,你可以将要运行的命令写入BAT中,运行DB2命令
示例:
db2 connect to bras user bras using 888888
db2 "export to D:\sqlldr\data\20091207\fhdgckfhz.del of del select * from BRAS.FHDGCKFHZ"
db2 "export to D:\sqlldr\data\20091207\fhdgckmxz.del of del select * from BRAS.FHDGCKMXZ"
db2 "export to D:\sqlldr\data\20091207\fhdkfhz.del of del select * from BRAS.FHDKFHZ"
db2 connect reset

这些写成一个bat文件,XXX.bat

然后在命令行里直接执行

db2cmd -i XXX.bat

类似于MYSQL的命令行

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。