title: How to stream remote output from psexec process
body: <p>I'm trying to run a batch file on a remote system and get the output locally (the batch file runs an SSIS script that has a bunch of output). I can get the remote file to run just fine, but I get no output from it on the local machine.</p>
  
  <p>My code (note, I was trying "ipconfig /all" just as a test):</p>
  
  <pre><code>public RunRemoteProcess() {
  
      _process = new Process();
      _process.StartInfo = new ProcessStartInfo
      {
          UseShellExecute = false,
          RedirectStandardOutput = true,
          RedirectStandardError = true,
          CreateNoWindow = true,
          FileName = string.Concat(AppDomain.CurrentDomain.BaseDirectory, @"Resources\psexec.exe"),
          Arguments = "\\remotePCName ipconfig /all"
      };
  
      _process.OutputDataReceived += OutputDataHandler;
      _process.ErrorDataReceived += ErrorDataHandler;
  
      _process.Start();
      _process.BeginOutputReadLine();
      _process.BeginErrorReadLine();
  
  }
  
  // _logger below is just a class that writes the data to a file
  private void OutputDataHandler(object sender, DataReceivedEventArgs e) {
      _logger.Info(e.Data);
  }
  
  private void ErrorDataHandler(object sender, DataReceivedEventArgs e) {
      _logger.Info(e.Data);
  }
  </code></pre>
  
  <p>I've found over SO questions/answers that mention using <code>WaitForExit</code> but I don't want to write the entire output when it finishes; I want to stream it as it's received.</p>
  
  <p>I've also tried added <code>RedirectStandardInput = true</code> to the ProcessStartInfo (as some answers said that worked) but it didn't change anything for me.</p>