关于调用CMD的问题!急!
kneek 2007-05-10 09:56:26 我调用AS400的Client Access从Db2数据库下载数据到文件使用rtopcb.exe
private string RunCmd(string strCmd)
{
string rInfo;
try
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd.exe");
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcessStartInfo.Arguments = " /c " + strCmd;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
rInfo = myStreamReader.ReadToEnd();
myProcess.WaitForExit();
myProcess.Close();
rInfo = strCmd +"\r\n"+ rInfo;
return rInfo;
}
catch(Exception ex)
{
return ex.Message;
}
}
调用如下:
private void cmdExec_ServerClick(object sender, System.EventArgs e)
{
Response.Write(RunCmd("rtopcb /s /i "+Server.MapPath(".")+"\\script\\"+tmpCheck.ID+".dtf"));
}
打出来的信息如下:
rtopcb /s /i D:\基础数据平台\ViewTable\script\05080157.dtf IBM iSeries Access Windows 版版本 5 发行版 2 级别 0 从 iSeries 传送数据 (C) Copyright IBM Corporation and Others 1984, 2002. All rights reserved. U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Licensed Materials - Property of IBM 传送文件:D:\基础数据平台\ViewTable\script\05080157.dtf
说明外部程序是运行了可是没有取数据。
如果上面的命令直接在cmd.exe下运行结果如下:
IBM iSeries Access Windows 版
版本 5 发行版 2 级别 0
从 iSeries 传送数据
(C) Copyright IBM Corporation and Others 1984, 2002. All rights reserved.
U.S. Government Users Restricted Rights - Use, duplication or disclosure
restricted by GSA ADP Schedule Contract with IBM Corp.
Licensed Materials - Property of IBM
传送文件:D:\基础数据平台\ViewTable\script\05080157.dtf
接收成功完成。
已传送的行:1
上面两个的不同就是一个取到了数据另一个没有。如果我把命令改为“del c:\test.txt”,也是一样的结果根本就不delete文件请高手帮帮我。