概要
cscの作法、調べてみた。
練習問題やってみた。
練習問題
c#で、コンソールアプリの結果を取得せよ。
写真
サンプルコード
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
class form1: Form {
form1() {
Text = "Checker";
ClientSize = new Size(300, 300);
Process process = new Process();
process.StartInfo.FileName = "test1.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.EnableRaisingEvents = true;
process.StartInfo.Arguments = "";
process.Exited += (s, evt) => {
process.Dispose();
};
process.OutputDataReceived += new DataReceivedEventHandler((_sender, _e) => {
if (!String.IsNullOrEmpty(_e.Data))
{
Console.WriteLine(_e.Data);
if (_e.Data == "1")
{
MessageBox.Show("hit!");
}
}
});
process.Start();
process.BeginOutputReadLine();
}
[STAThread]
public static void Main() {
Application.Run(new form1());
}
}
以上。