我在执行外部命令时使用的CMD,但是为什么ExitCode总是不为0呢?
ExitCode总是为1或是其它值(1为不成功,成功为0),有没有办法解决?
代码如下:
System.Diagnostics.Process p=new System.Diagnostics.Process();
p.StartInfo.FileName="cmd.exe";
p.StartInfo.UseShellExecute=false;
p.StartInfo.RedirectStandardInput=true;
p.StartInfo.RedirectStandardOutput=true;
p.Start();
p.StandardInput.WriteLine(@" cd "+basepath);
string disk=basepath.Substring(0,2);
p.StandardInput.WriteLine("" +disk+ "");
string cmd=" xxxx -u "+UserName+" -p "+Password+" "+TestCenter+" -f "+path;
p.StandardInput.WriteLine(cmd);
}p.StandardInput.WriteLine("exit");
p.WaitForExit();
if((p.ExitCode==0)) {
returnvalue=true;
}
ExitCode总是为1或是其它值(1为不成功,成功为0),有没有办法解决?
代码如下:
System.Diagnostics.Process p=new System.Diagnostics.Process();
p.StartInfo.FileName="cmd.exe";
p.StartInfo.UseShellExecute=false;
p.StartInfo.RedirectStandardInput=true;
p.StartInfo.RedirectStandardOutput=true;
p.Start();
p.StandardInput.WriteLine(@" cd "+basepath);
string disk=basepath.Substring(0,2);
p.StandardInput.WriteLine("" +disk+ "");
string cmd=" xxxx -u "+UserName+" -p "+Password+" "+TestCenter+" -f "+path;
p.StandardInput.WriteLine(cmd);
}p.StandardInput.WriteLine("exit");
p.WaitForExit();
if((p.ExitCode==0)) {
returnvalue=true;
}
The code that the associated process specified when it terminated.
开发人员通常使用为零的 ExitCode 值指示成功退出,并通过非零值指出错误,调用方法可使用非零值来标识进程不正常终止的原因。虽然不必遵从这些准则,但这些准则是约定。