我在C#中有一个工作代码(当然是在另一台机器上),在移植之后,它不再存在。该代码在命令提示符下向perforce服务器运行命令,并读取输出以查找特定字符串。代码是:
string result="";
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
//Start the process
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
//Attach output for reading
System.IO.StreamReader sOut = proc.StandardOutput;
System.IO.StreamWriter sIn = proc.StandardInput;
sIn.WriteLine(@"p4 changelists -m 1 -s submitted //<SOME_PATH_HERE>");
proc.WaitForExit(500);
sIn.WriteLine("EXIT");
while((result=sOut.ReadLine()) != null)
{
if(result != "")
{
if(result.Substring(0,6) == "Change")
{
//get Changelist number
result = result.Substring(7,6);
break;
}
}
}
if((result == "") || (result == null)) //if perforce goes down
{
问题是当我发出一些cmd.exe知名命令(例如DIR和...)时,我可以在结果变量中逐行看到输出,但是对于p4的特殊命令,结果字符串为空。
我搜索了我的问题,可能最接近的问题与CASPOL有关!
我不知道这是什么精妙之处,以及如何摆脱它。
任何帮助将不胜感激。