How do I write to command line from a WPF application?(如何从 WPF 应用程序写入命令行?)
问题描述
您好,我知道如何写入控制台,但是如果我在程序中写入控制台并从命令行调用我的程序,它将不会显示任何内容.
Hi I know how to write to console but if I write to console in my program and call my program from the command line it won't display anything.
如何做到这一点,以便当我说 Console.WriteLine 或 Console.Out.Writeline 时,ir 打印到调用它的命令提示符而不是其他地方?
How do I make it so that when I say Console.WriteLine or Console.Out.Writeline ir prints to the command prompt from which it was called and not somewhere else?
我又一次知道如何做 Console.WriteLine 所以不是这样 :-p 除非我做错了.
Once again I know how to do Console.WriteLine so it's not that :-p unless I'm doing it wrong.
据我所知,这可能与 Console.SetOut(TextWriter t) 有关
From what I can tell it's probably something to do with Console.SetOut(TextWriter t)
这是一个 WPF 应用程序,我需要它将数据发布到命令行,同时在启动时仍保留 GUI.我已经三重检查并且我的代码命中了打印行,我实际上可以看到打印到 Visual Studio 输出窗口的行,当我在没有 VS 的情况下手动运行它时,它不会显示在命令行中.
this is a WPF application and I need it to post its data to the command line while still retaining the GUI at startup. I've triple checked and my code hits the print lines, I can actually see the lines being printed to the Visual Studio output window, it just won't display in the command line when I run it manually without VS.
如果可能,我需要有条件地显示控制台.即如果从命令行运行(甚至使用命令参数),显示或发布到提示符,否则不要.
If possible I need to conditionally have the console display. ie if run from command line (or even with command arguments), display or post to the prompt, otherwise do not.
推荐答案
将项目类型设置为控制台应用程序"而不是Windows 应用程序".这将导致应用程序附加到启动它的控制台(如果还没有控制台,则创建一个控制台).
Set the project type to "Console Application" instead of "Windows Application". This will cause the Application to attach to the console from which it was launched (or create a console if there was not one already).
这篇关于如何从 WPF 应用程序写入命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 WPF 应用程序写入命令行?
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01