【发布时间】:2019-11-08 16:00:36
【问题描述】:
我在 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 和 ... p>
我用谷歌搜索了我的问题,最接近的可能与 CASPOL 相关!?
我不知道它是什么以及如何摆脱它。
任何帮助将不胜感激。
【问题讨论】:
标签: c# asp.net stdout stdin perforce