2013-01-25 2 views
0

저는 Streams의 초보자입니다. Process의 StandardOutput을 리디렉션하고 다른 곳에서 소비 될 수 있도록 StandardOutput Stream을 반환하는 함수를 작성하려고합니다. 메서드에서 Process.StandardOutput Stream을 반환하면 해당 Stream은 어떻게 저장됩니까? 그것이 소비 될 때까지 그냥 어딘가에 살고 있습니까? 최대 크기가 있습니까? , CompareStreams()에 따라서Process.StandardOutput 스트림은 어떻게 저장됩니까?

public Stream GetStdOut(string file) 
    { 
     _process = new Process(file); 
     _process.StartInfo.UseShellExecute = false; 
     _process.StartInfo.RedirectStandardOutput = true; 
     _process.Start(); 
     return _process.StandardOutput; 
    } 

    public bool CompareStreams() 
    { 
     Stream s1 = GetStdOut("somefile.exe"); 
     Stream s2 = GetStdOut("anotherfile.exe"); 

     using (StreamReader sr1 = new StreamReader(s1)) 
     using (StreamReader sr2 = new StreamReader(s2)) 
     { 
      string line_a, line_b; 
      while ((line_a = sr1.ReadLine()) != null && 
        (line_b = sr2.ReadLine()) != null) 
      { 
       if (line_a != line_b) 
        return false; 
      } 
      return true; 
     } 
    } 

내가 스트림에 대한 스트림 (S1) I가 발생하고있어 동안 데이터와 관련된 데이터의 양에 대해 걱정해야 할 : 여기

내가 지금까지 가지고 그 일부 예제 코드입니다 s2? 아니면 별 문제가 아닌가?

답변

2

Stream 개체는 모든 표준 출력 데이터로 즉시 채워지지 않습니다.

프로세스가 실행되면 버퍼에 쓰고 버퍼가 가득 차면 버퍼에서 읽을 때까지 고정됩니다.

버퍼에서 읽으면 더 많은 데이터를 쓰는 프로세스의 공간이 정리됩니다.

+0

즉, 버퍼링 된 출력 스트림입니다. –

관련 문제