After tried calling paexec from C# program, it can't capture any stderr, tested my program on psexec, it can capture stderr, however for paexec, if runs from a command shell, it can see the stderr, but can't see it appeared on my program. Is this fault on paexec?

void Main() { var cmdargs =@"machine c:windowssystem32inetsrvappcmd list apppool"; for(int i=0;i<10;i++) { Debug.WriteLine("Trial #{0}",i); psexec(cmdargs, true); } }

// ISSUE: if paexec used, nothing from stderr is captured at all (stdout seems ok) // (with psexec, stderr is captured, but due to other reasons psexec fails) string pexec() {return "paexec.exe";} // Define other methods and classes here

void psexec(string cmdargs, bool showOutput=true) { // uses method described in // Read at least one stream asynchronously to avoid deadlock condition StringBuilder outputTxt=new StringBuilder(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName =pexec(); startInfo.Arguments = cmdargs; Debug.WriteLine(cmdargs); startInfo.UseShellExecute = false; startInfo.RedirectStandardError = true; startInfo.RedirectStandardOutput = true; startInfo.CreateNoWindow = true; Process process = new Process(); process.StartInfo = startInfo; process.OutputDataReceived += new DataReceivedEventHandler( (object proc,DataReceivedEventArgs outline)=>{ if (!String.IsNullOrEmpty(outline.Data)) outputTxt.Append(Environment.NewLine+outline.Data); }); process.Start(); process.BeginOutputReadLine(); string errTxt=process.StandardError.ReadToEnd();

    Debug.WriteLine("Process exit code: {0}",process.ExitCode);
    if (showOutput){


asked 22 Feb '16, 21:51

flyfox's gravatar image

accept rate: 0%

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 22 Feb '16, 21:51

Seen: 2,991 times

Last updated: 22 Feb '16, 21:51