gpt4 book ai didi

c# - 在 Windows 10 通用应用程序平台上运行 CMD 命令

转载 作者:太空宇宙 更新时间:2023-11-03 21:14:22 25 4
gpt4 key购买 nike

<分区>

如何通过 C# 在 Windows 10(现代)通用应用程序平台 (UWP) 上运行 CMD 命令?我尝试使用此代码(它适用于 Windows 窗体应用程序:

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

谢谢大家

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com