我用C#编写一个控制台应用程序,处理一些数据,然后打印出结果。直到结果都可以有一个小动画。(/ - |)和进度百分比(XX%),这是不断更新
I have a console application written in C# which processes some data then prints the results. Until the results are available there is a little animation ( / - | ) and progress percentage ( xx% ) which is constantly updating.
显然,如果用户重定向我的应用程序的输出,这将被打印到输出重定向到文本文件。如果可能的话,我想避免这种情况。
Obviously if the user redirects the output of my application this will be printed to the text file where output is redirected to. If possible I would like to avoid this.
那么,有没有一种方法来检测,如果我的应用程序的输出重定向? 我只考虑与一个指定的参数运行时显示进度指标,但我希望有人将有一个很好的回答我。
So is there a way to detect if the output of my application is redirected? I am considering only showing the progress indicators when run with a specified parameter, but I'm hoping someone will have a good answer for me.
推荐答案
您不能。重定向输出是完全和完全执行程序的范围之内。您可以但是添加一个命令行选项来禁用pretty的输出,以便它可以用来重定向了。
You can't. Redirected output is totally and wholly outside the scope of the executing program. You can however add a commandline option to disable your pretty output so that it can be used redirected too.
相关推荐
最新文章