Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在C#windows窗体应用程序visual studio 2010中隐藏命令提示符_C#_Visual Studio 2010_Process_Cmd - Fatal编程技术网

无法在C#windows窗体应用程序visual studio 2010中隐藏命令提示符

无法在C#windows窗体应用程序visual studio 2010中隐藏命令提示符,c#,visual-studio-2010,process,cmd,C#,Visual Studio 2010,Process,Cmd,我已经在C#visual studio 2010中提出了一个应用程序。在这个应用程序中,我向cmd发送ping命令,并在RichTextBox中接收cmd的输出。这是我的密码:- void proc_OutputDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { string newLine = e.Data.Trim() + Environment.NewLin

我已经在C#visual studio 2010中提出了一个应用程序。在这个应用程序中,我向
cmd
发送
ping
命令,并在
RichTextBox
中接收
cmd
的输出。这是我的密码:-

void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    if (e.Data != null)
    {
        string newLine = e.Data.Trim() + Environment.NewLine;
        MethodInvoker append = () => txtOutput.Text += newLine;
        txtOutput.BeginInvoke(append);
    }
}
private void btnPing_Click(object sender, EventArgs e)
{
    string command = "/c ping " + txtPing.Text;

    ProcessStartInfo procStartInfo = new ProcessStartInfo("CMD", command);

    Process proc = new Process();
    proc.StartInfo = procStartInfo;
    proc.Start();

    procStartInfo.RedirectStandardOutput = true;
    procStartInfo.UseShellExecute = false;
    proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
    proc.Start();
    proc.BeginOutputReadLine();
    proc.WaitForExit();
}
我的代码运行得很好,但问题是当我点击
start
按钮时,
cmd
也会弹出。我想隐藏这个
cmd
,因为我只想在
RichTextBox中显示输出。
所以,我的问题是,如何在我的应用程序中隐藏
cmd
。 这是我的问题的屏幕截图。

试试这个:

proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

这对我很有效。

尝试添加这些行。这对我有用

 procStartInfo.CreateNoWindow = true;
 procStartInfo.UseShellExecute = false;
 procStartInfo.RedirectStandardOutput = true;

谢谢,但它不起作用请尝试以下操作:procStartInfo.StartInfo.UseShellExecute=false;procStartInfo.StartInfo.CreateNoWindow=true;连同语法Imentioned@Partha请拿定主意。答案说一件事,评论另一件事。得到我的答案,它是proc.StartInfo.WindowStyle=ProcessWindowStyle.Hidden@Partha请在这个单一答案中提供所有可能的解决方案,让人们不要阅读所有评论(他们甚至可能不会这样做)。一个cmd窗口仍然存在,显示ping结果。对该窗口也做同样的操作@Tabish那是因为你做得不对。我明白了,命令有点不同,它是proc.StartInfo.WindowStyle=ProcessWindowStyle.Hidden;无论如何,谢谢你的帮助,兄弟,你的方法也应该是正确的