2021. 1. 25. 08:12ㆍ카테고리 없음
대상 프로그램 (test1111.exe) 을 백그라운드로 실행하며 , 대상 프로그램에서 출력한 값을 읽어와
현재 프로그램에서 출력하는 프로그램
using System;
using System.Diagnostics;
namespace backgroundStart
{
class Program
{
static void Main(string[] args)
{
// 경로 및 명령 줄에 대한 인수
string ApplicationPath = @"C:\Users\user\Desktop\test1111.exe";
string ApplicationArguments = "-c -x";
Process Proc = new Process();
Proc.StartInfo.FileName = ApplicationPath;
Proc.StartInfo.Arguments = ApplicationArguments;
// 옵션
Proc.StartInfo.UseShellExecute = false; // 스트림을 읽는데 필요
Proc.StartInfo.CreateNoWindow = false; // 새 창에서 시작하지 않음.
Proc.StartInfo.RedirectStandardOutput = true; // 실행시킨 프로그램의 출력을 얻는다.
Proc.Start();
Proc.WaitForExit(); // 종료시까지 대기
string Result = Proc.StandardOutput.ReadToEnd(); // 실행시킨 프로그램의 출력을 읽는다.
Console.WriteLine("aaa" + Result);
Console.ReadLine();
}
}
}