C#
[C#] 윈폼으로 콘솔명령 실행하기
요지
2012. 10. 10. 16:27
윈폼으로 콘솔명령 실행하기 | 한진수 | 평점: 없음 | 조회: 1895 |
아주 쉬운 방법이 있습니다.
필요한 콘솔명령 문자열을 구성 후 임시 배치파일(.bat)을 만드시고,
해당 배치파일을 Process.Start() 로 실행시키시면 아주 간단히 원하는 작업을 하실 수 있습니다.

배치 명령 문자열만 잘 구성하면, 연속된 작업도 가능하겠죠?(^^)
필요한 콘솔명령 문자열을 구성 후 임시 배치파일(.bat)을 만드시고,
해당 배치파일을 Process.Start() 로 실행시키시면 아주 간단히 원하는 작업을 하실 수 있습니다.
실행 버튼 코드
01 private void button_Excute_Click(object sender, EventArgs e)
02 {
03 string batchFileName = @"tempBatch.bat";
04
05 System.IO.File.WriteAllText(batchFileName, txt_Command.Text);
06
07 ProcessStartInfo psInfo = new ProcessStartInfo(batchFileName);
08 psInfo.CreateNoWindow = true;
09 psInfo.UseShellExecute = false;
10 psInfo.RedirectStandardOutput = true;
11
12 txt_Result.Text = Process.Start(psInfo).StandardOutput.ReadToEnd();
13 }
01 private void button_Excute_Click(object sender, EventArgs e)
02 {
03 string batchFileName = @"tempBatch.bat";
04
05 System.IO.File.WriteAllText(batchFileName, txt_Command.Text);
06
07 ProcessStartInfo psInfo = new ProcessStartInfo(batchFileName);
08 psInfo.CreateNoWindow = true;
09 psInfo.UseShellExecute = false;
10 psInfo.RedirectStandardOutput = true;
11
12 txt_Result.Text = Process.Start(psInfo).StandardOutput.ReadToEnd();
13 }
배치 명령 문자열만 잘 구성하면, 연속된 작업도 가능하겠죠?(^^)