Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Commands Process Redirection , +
Hi all,
its my first time posting a coding question.. I am getting crazy with the following case (searching the internet for a couple of days):
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 user interaction. therefore i have to capture ALL output data (standard output, standard error AND CONSOLE).
Looking at the following test batch should make the case more clear:
2: ECHO StdOut
3: ECHO StdErr 1>&2
4: ECHO Cons>CON
I am able to capture lines 2+3, but not 4 (used by some programs).
I have also tried powershell instead of cmd.exe as starting point, but same result.
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?
any help is really appreciated. Thanks a lot!
Posted 16-Jan-12 21:30pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I've encountered the same issue. You can capture ALL of plink's command-line output by executing it through a windows shell script. eg.

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c C:\tools\plink -load "& WScript.Arguments(0) &" "& WScript.Arguments(1) )
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
WScript.StdOut.WriteLine strText
Then call the windows shell script via cscript. eg.
cscript C:\\tools\\executePlink.vbs argument1 argument2
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use System.Diagnostics.Process.Start with re-directed output streams StandardOutput and StandardError, please see[^].
You can find a code sample with redirection here:[^].
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

thanks for the suggestion. Unfortunately I was not precise with my explanation: I am using a Process with asynchronous redirection of StandardOutput and StandardError, but I have no idea how to capture the other output send to the cmd process.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 239
1 Sarvesh Kumar Gupta 185
2 George Jonsson 154
3 ArunRajendra 144
4 Richard MacCutchan 140

Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid