Nefunkční čtení,zápis CMD
CMD
namespace CMD
{
public partial class Form1 : Form
{
StreamWriter vstup;
Process cmd;
bool spusteno = false;
public Form1()
{
InitializeComponent();
cmd = new Process();
}
private void button3_Click(object sender, EventArgs e)
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;
cmd.StartInfo = processStartInfo;
cmd.OutputDataReceived += cmd_OutputDataReceived;
spusteno = cmd.Start();
vstup = cmd.StandardInput;
cmd.BeginOutputReadLine();
cmd.EnableRaisingEvents = true;
cmd.Exited += cmd_Exited;
if (spusteno)
{
label3.Text = "OK";
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = false;
}
}
void cmd_Exited(object sender, EventArgs e)
{
this.Invoke(new MethodInvoker(delegate
{
cmd.CancelOutputRead();
spusteno = false;
label3.Text = "VYPNUTO";
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
textBox2.Text = "";
}));
}
void cmd_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data)) //pokud prijate data neco obsahujou
{
this.Invoke(new MethodInvoker(delegate
{
textBox2.Text += Environment.NewLine + e.Data;
textBox2.SelectionStart = textBox2.Text.Length;
textBox2.ScrollToCaret();
textBox2.Refresh();
}));
}
}
private void button1_Click(object sender, EventArgs e)
{
if (spusteno)
{
vstup.WriteLine(textBox1.Text);
textBox1.Text = "";
}
}
private void button2_Click(object sender, EventArgs e)
{
cmd.Kill();
}
}
}
Neformátovaný
Přidáno: 24.6.2014
Expirace: Neuvedeno