在进程中从C#运行Powershell脚本。脚本运行正常,但控制台只是挂在那里等待。
这是我的代码:
public static int RunPowershellScript(string ps)
{
int errorLevel;
ProcessStartInfo processInfo;
Process process;
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
processInfo = new ProcessStartInfo("powershell.exe", "-File " + ps);
processInfo.CreateNoWindow = false;
processInfo.UseShellExecute = false;
process = Process.Start(processInfo);
process.WaitForExit();
errorLevel = process.ExitCode;
process.Close();
return errorLevel;
}
我需要做些什么来告诉这个方法在脚本完成后才离开?
谢谢!