|
|
发表于 2013-9-24 21:05:57
|
显示全部楼层
广东省深圳市
这个C#的行不行
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.IO;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Process p = null;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- p = new Process();
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.FileName = "cmd.exe";
- p.StartInfo.RedirectStandardInput = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardError = true;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- p.Start();
- p.StandardInput.WriteLine(textBox1.Text);
- p.StandardInput.WriteLine("exit");
- StreamReader sr = p.StandardOutput;
- string Line = sr.ReadLine();
- while (!sr.EndOfStream) {
- textBox2.AppendText(Line+"\r\n");
- Line += sr.ReadLine();
- }
- p.WaitForExit();
- p.Close();
- sr.Close();
- }
- }
- }
复制代码 |
|