[英]Using Process.Start in C#
我想從 C# 啟動 python 應用程序,所以我使用方法 Process。 在我運行它並單擊我得到的按鈕后
System.ComponentModel.Win32Exception: 系統找不到指定的文件
在任一情況下。 怎么了?
int counter = 0;
private void button1_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
counter++;
TextBox1.Text = counter.ToString();
//Process.Start("Python.exe", "C:\\Users\\kamil\\source\\PythonApplication2\\PythonApplication2.py");
Process.Start("IExplore.exe", "www.northwindtraders.com");
}
問題可能是 python.exe 和我 explore.exe 的完整路徑。 您可以為它們指定完整路徑。 甚至可以將路徑添加到 PATH 環境變量。 如果在 PATH 環境變量中指定了路徑,則不需要指定完整路徑。 你可以像這樣改變它:
var old = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine)
var new = old + @"Full path, here you don't need to escape double quotes."
Environment.SetEnvironmentVariable("PATH", new, EnvironmentVariableTarget.Machine)
在 @"" 中包含路徑是一個很好的做法,這里不需要轉義特殊字符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.