要隐藏cmd提示屏幕 [英] Want to hide the cmd prompt screen
本文介绍了要隐藏cmd提示屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了一个实用程序,该实用程序将获取列表中所有服务器的时间。
I have developed a utility which will get time of all servers in the list.
System.Diagnostics.Process p;
string server_name = "";
string[] output;
p = new System.Diagnostics.Process();
p.StartInfo.FileName = "net";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StandardOutput.ReadLine().ToString()
在执行此代码时。出现 Cmd 提示屏幕。我想向用户隐藏它。我该怎么办?
While executing this code. Cmd prompt screens are coming. I want to hide it from the user. What can I do for it?
推荐答案
您可以告诉进程不使用窗口或将其最小化:
You can tell the process to use no window or to minimize it:
// don't execute on shell
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
// don't show window
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
带有 UseShellExecute = false
,您可以重定向输出:
with UseShellExecute = false
you may redirect the output:
// redirect standard output as well as errors
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
执行此操作时,应使用输出缓冲区的异步读取,以避免由于过度填充而导致死锁缓冲区:
When you do this, you should use asynchronous reading of the output buffers to avoid a deadlock due to overfilled buffers:
StringBuilder outputString = new StringBuilder();
StringBuilder errorString = new StringBuilder();
p.OutputDataReceived += (sender, e) =>
{
if (e.Data != null)
{
outputString.AppendLine("Info " + e.Data);
}
};
p.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
{
errorString.AppendLine("EEEE " + e.Data);
}
};
这篇关于要隐藏cmd提示屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文