Note that there are some explanatory texts on larger screens.

plurals
  1. POCapture ALL (stdout, stderr AND CON) output of cmd executing plink with C# (std out+err ok, CON not working)
    text
    copied!<p>I want to open SSH connections from c# via opening a process and running plink. All output should be collected and depending on the results the program will fire actions to the ssh. My big problem is, that i am using a couple if different scripts and i need (automated) user interaction. Therefore i have to capture ALL output data (standard output, standard error AND CONSOLE).</p> <p>Looking at the following test batch should make the case more clear:</p> <pre><code>1: @ECHO OFF 2: ECHO StdOut 3: ECHO StdErr 1&gt;&amp;2 4: ECHO Cons&gt;CON </code></pre> <p>The code is like:</p> <pre><code>Process process; Process process; process = new Process(); process.StartInfo.FileName = @"cmd.exe"; process.StartInfo.Arguments = "/c test.bat"; process.StartInfo.UseShellExecute = false; process.StartInfo.ErrorDialog = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardInput = true; process.Start(); process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived); process.ErrorDataReceived += new DataReceivedEventHandler(process_OutputDataReceived); process.BeginOutputReadLine(); process.BeginErrorReadLine(); StreamWriter inputWriter = process.StandardInput; [...] </code></pre> <p>I am able to capture lines 2+3, but not 4 (used by some programs). I have also tried powershell (or directly plink) instead of cmd.exe as starting point, but same result.</p> <p>Is there any way in c# to capture the console out as well or do you know any third party command line being able to redirect CON out to stdout or something like this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload