• 大小: 30KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-13
  • 语言: C#
  • 标签: C#  实时  管道  Thread  

资源简介

实时获取DOS的输出结果,显示在C#窗口中。 为了避免阻塞主线程,把执行过程放在一个新的Thread中,防止了DOS执行中,C#窗口“假死”现象。 网上有个管道实现DOS输出的程序,没看懂,也不能编译,却被各网站,很多人转载。 CSDN上有个程序,可以捕获dos输出,但执行过程中窗口会”假死“,这里用新的线程避免了假死。可以在vs.net 2005上运行

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using System.IO;
//using System.Collections.Generic;
namespace Guandao
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            Process proc = new Process();
            proc.StartInfo.FileName = “cmd.exe“;
            //proc.StartInfo.WorkingDirectory = 
            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.RedirectStandardInput = true;
            proc.Start();
            proc.StandardInput.WriteLine(this.textBox1.Text);
            proc.StandardInput.WriteLine(“exit“);
            StreamReader reader = proc.StandardOutput;
            string line = reader.ReadLine();
            while (!reader.EndOfStream)
            {
                this.richTextBox1.AppendText(line+“\r“);
                this.richTextBox1.Selectionstart = this.richTextBox1.Text.Length;
                this.richTextBox1.ScrollToCaret();
                line = reader.ReadLine();
            }
            proc.WaitForExit();
            proc.Close();
            reader.Close();
        }


    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      20480  2010-01-23 00:02  Guandao\Guandao\bin\Debug\Guandao.exe

     文件      22016  2010-01-23 00:02  Guandao\Guandao\bin\Debug\Guandao.pdb

     文件       5632  2005-11-11 22:25  Guandao\Guandao\bin\Debug\Guandao.vshost.exe

     文件       1590  2010-01-23 00:01  Guandao\Guandao\Form1.cs

     文件       3858  2010-01-23 00:01  Guandao\Guandao\Form1.Designer.cs

     文件       5814  2010-01-23 00:01  Guandao\Guandao\Form1.resx

    .......      3221  2010-01-22 00:19  Guandao\Guandao\Guandao.csproj

     文件        842  2010-01-23 00:02  Guandao\Guandao\obj\Debug\Guandao.csproj.GenerateResource.Cache

     文件      20480  2010-01-23 00:02  Guandao\Guandao\obj\Debug\Guandao.exe

     文件        180  2010-01-23 00:02  Guandao\Guandao\obj\Debug\Guandao.Form1.resources

     文件      22016  2010-01-23 00:02  Guandao\Guandao\obj\Debug\Guandao.pdb

     文件        180  2010-01-23 00:02  Guandao\Guandao\obj\Debug\Guandao.Properties.Resources.resources

     文件        604  2010-01-23 00:02  Guandao\Guandao\obj\Guandao.csproj.FileListAbsolute.txt

    .......       466  2010-01-22 00:13  Guandao\Guandao\Program.cs

    .......      1162  2010-01-22 00:13  Guandao\Guandao\Properties\AssemblyInfo.cs

    .......      2870  2010-01-22 00:13  Guandao\Guandao\Properties\Resources.Designer.cs

    .......      5612  2010-01-22 00:13  Guandao\Guandao\Properties\Resources.resx

    .......      1092  2010-01-22 00:13  Guandao\Guandao\Properties\Settings.Designer.cs

    .......       249  2010-01-22 00:13  Guandao\Guandao\Properties\Settings.settings

    .......       910  2010-01-22 00:13  Guandao\Guandao.sln

    ..A..H.     12800  2010-01-23 00:03  Guandao\Guandao.suo

     目录          0  2010-01-22 23:54  Guandao\Guandao\obj\Debug\TempPE

     目录          0  2010-01-23 00:02  Guandao\Guandao\bin\Debug

     目录          0  2010-01-23 00:02  Guandao\Guandao\obj\Debug

     目录          0  2010-01-22 23:54  Guandao\Guandao\bin

     目录          0  2010-01-23 00:02  Guandao\Guandao\obj

     目录          0  2010-01-22 23:54  Guandao\Guandao\Properties

     目录          0  2010-01-23 00:01  Guandao\Guandao

     目录          0  2010-01-22 23:54  Guandao

----------- ---------  ---------- -----  ----

............此处省略2个文件信息

评论

共有 条评论