如何从 WPF 应用程序写入命令行? [英] How do I write to command line from a WPF application?

查看:24
本文介绍了如何从 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 应用程序写入命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆