c#调用CMD执行程序
string str = @"cd c:\temp"
string str2 = "echo y>c.txt "
string str3 = "abaqus job=footbridge2017-10-11-2 int <c.txt "
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.StartInfo.RedirectStandardError = true
p.StartInfo.CreateNoWindow = true
p.Start()
//向cmd窗口发送输入信息
p.StandardInput.WriteLine(str)
p.StandardInput.WriteLine(str2)
p.StandardInput.WriteLine(str3)
p.StandardInput.WriteLine("exit")
p.StandardInput.AutoFlush = true
//p.StandardInput.WriteLine("exit")
//向标准输入写入要执行的命令。这里使用&是批处理命令的符号,表示前面一个命令不管是否执行成功都执行后面(exit)命令,如果不执行exit命令,后面调用ReadToEnd()方法会假死
//同类的符号还有&&和||前者表示必须前一个命令执行成功才会执行后面的命令,后者表示必须前一个命令执行失败才会执行后面的命令
//获取cmd窗口的输出信息
string output = p.StandardOutput.ReadToEnd()
txt.Text = output
p.WaitForExit()
p.Close()
Console.WriteLine(output)