CMD into GUI
java
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace ModifiedCommandPrompt
{
public class CommandPrompt
{
private Process process;
private Control input, output, error;
public CommandPrompt(Control input, Control output, Control error)
{
process = new Process() { EnableRaisingEvents = true };
process.StartInfo = new ProcessStartInfo("cmd.exe")
{
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
};
process.Start();
process.OutputDataReceived += (o, e) =>
{
output.Invoke(new MethodInvoker(() =>
{
output.Text += e.Data + Environment.NewLine;
error.Text = string.Empty;
}));
};
process.ErrorDataReceived += (o, e) =>
{
error.Invoke(new MethodInvoker(() => { error.Text = e.Data; }));
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
public void Execute(string command)
{
process.StandardInput.WriteLine(command);
}
}
}
Neformátovaný
Přidáno: 24.6.2014
Expirace: Neuvedeno