我如何写命令行从WPF应用程序? [英] How do I write to command line from a WPF application?
问题描述
您好我知道该怎么写安慰,但如果我写在我的计划去安慰,并调用命令行也不会显示任何东西我的程序。
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红外打印到命令提示符从它被称为,而不是别的地方?
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屋!