如何通過C#在Windows 10(現代)通用應用程序平臺(UWP)上運行CMD命令? 我嘗試使用此代碼(它的Windows上運行形成應用:在Windows 10通用應用程序平臺上運行CMD命令
using System.Diagnostics;
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine("the command");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
,但我有一個錯誤:
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) OneSpot C:\Users\reuve\Documents\Visual Studio 2015\Projects\app\app\MainPage.xaml.cs 37 Active
和:
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Console' does not exist in the current context OneSpot C:\Users\reuve\Documents\Visual Studio 2015\Projects\app\app\MainPage.xaml.cs 49 Active
謝謝大家
是那個確切的代碼,或者是某個函數的某些地方? – crashmstr
你根本無法在UWP應用程序中運行可執行文件。 –
最後兩個代碼是錯誤的副本。 –