Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- namespace CmdInGM
- {
- public class Cmd
- {
- private StringBuilder _builder;
- private Process _console;
- public double StartCmd()
- {
- try
- {
- _builder = new StringBuilder();
- _builder.Clear();
- _console = new Process();
- _console.StartInfo.UseShellExecute = false;
- _console.StartInfo.RedirectStandardOutput = true;
- _console.StartInfo.RedirectStandardInput = true;
- _console.StartInfo.CreateNoWindow = true;
- _console.StartInfo.FileName = "cmd.exe";
- _console.OutputDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e)
- {
- _builder.AppendLine(e.Data);
- });
- _console.Start();
- _console.BeginOutputReadLine();
- }
- catch { return -1; }
- return 1;
- }
- public double StopCmd()
- {
- _console.Close();
- return 1;
- }
- public string ReadOutput()
- {
- string o = _builder.ToString();
- _builder.Clear();
- return o;
- }
- public double WriteInput(string input)
- {
- try
- {
- _console.StandardInput.WriteLine(input);
- }
- catch { return -1; }
- return 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement