Tag: cmd

从WPF Windows应用程序输出Console.WriteLine到实际控制台

背景:我正在努力为现有的WPF Windows应用程序添加命令行和批处理function。 当我在启动时检测到一些选项时,我禁止窗口出现,进行一些处理并立即退出。 现在,因为没有UI,我想将一些消息输出到stdout / stderr。 考虑以下代码: namespace WpfConsoleTest { public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { Console.WriteLine(“Start”); System.Threading.Thread.Sleep(1000); Console.WriteLine(“Stop”); Shutdown(0); } } } 当我从命令行运行时,我希望以下输出: Start Stop 但反而: C:\test>WpfConsoleTest.exe C:\test> 但是,您可以重定向输出: C:\test>WpfConsoleTest.exe > out.txt C:\test>type out.txt Start Stop 不幸的是,重定向到CON不起作用: C:\test>WpfConsoleTest.exe > CON C:\test> 另一个问题是WpfConsoleTest.exe在启动后立即退出。 所以: C:\test>WpfConsoleTest.exe > out.txt & […]

如何在processStartInfo中传递多个参数?

我想从c#代码运行一些cmd命令。 我跟着一些博客和教程得到了答案,但我有点困惑,即我应该如何传递多个参数? 我使用以下代码: System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; startInfo.FileName = “cmd.exe”; startInfo.Arguments = … 以下命令行代码的startInfo.Arguments值是什么? makecert -sk server -sky exchange -pe -n CN=localhost -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My MyAdHocTestCert.cer netsh http add sslcert ipport=127.0.0.1:8085 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF} clientcertnegotiation=enable