【发布时间】:2014-05-06 19:19:11
【问题描述】:
我的 wpf 应用程序调用 python 脚本来生成输出,该输出稍后会显示在 UI 中。如果用户的系统上没有安装 python,为了避免应用程序崩溃,我需要进行检查。目前我已经使用以下方法实现了这一目标
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"cmd.exe"; // Specify exe name.
start.Arguments = "python --version";
start.UseShellExecute = false;
start.RedirectStandardError = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardError)
{
string result = reader.ReadToEnd();
MessageBox.Show(result);
}
}
这可以完成工作,但会导致 cmd 黑色窗口暂时出现,这是非常不希望的。是否有解决方法来实现此目的或修复以避免出现窗口?
【问题讨论】:
-
也许添加 start.CreateNoWindow = true; ?