Advertisement
Guest User

CmdInGM

a guest
Jan 20th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7.  
  8. namespace CmdInGM
  9. {
  10.     public class Cmd
  11.     {
  12.         private StringBuilder _builder;
  13.         private Process _console;
  14.  
  15.         public double StartCmd()
  16.         {
  17.             try
  18.             {
  19.                 _builder = new StringBuilder();
  20.                 _builder.Clear();
  21.  
  22.                 _console = new Process();
  23.                 _console.StartInfo.UseShellExecute = false;
  24.                 _console.StartInfo.RedirectStandardOutput = true;
  25.                 _console.StartInfo.RedirectStandardInput = true;
  26.                 _console.StartInfo.CreateNoWindow = true;
  27.                 _console.StartInfo.FileName = "cmd.exe";
  28.                 _console.OutputDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e)
  29.                 {
  30.                     _builder.AppendLine(e.Data);
  31.                 });
  32.                 _console.Start();
  33.                 _console.BeginOutputReadLine();
  34.             }
  35.             catch { return -1; }
  36.             return 1;
  37.         }
  38.         public double StopCmd()
  39.         {
  40.             _console.Close();
  41.  
  42.             return 1;
  43.         }
  44.  
  45.         public string ReadOutput()
  46.         {
  47.             string o = _builder.ToString();
  48.             _builder.Clear();
  49.             return o;
  50.         }
  51.         public double WriteInput(string input)
  52.         {
  53.             try
  54.             {
  55.                 _console.StandardInput.WriteLine(input);
  56.             }
  57.             catch { return -1; }
  58.             return 1;
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement