且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

捕获执行plink的cmd的所有(stdout,stderr和CON)输出

更新时间:2023-02-22 14:19:14

您可以使用 System.Diagnostics.Process.Start 带有重定向输出流 StandardOutput StandardError ,请参阅http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx [ ^ ]。



您可以在此处找到带重定向的代码示例: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx [ ^ ]。



-SA
You can use System.Diagnostics.Process.Start with re-directed output streams StandardOutput and StandardError, please see http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].

You can find a code sample with redirection here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[^].

—SA






感谢您的建议。不幸的是,我对我的解释并不准确:我使用的是一个带有StandardOutput和StandardError异步重定向的进程,但我不知道如何捕获其他输出发送到cmd进程。



谢谢!
Hi,

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.

thanks!


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
Loop

Then call the windows shell script via cscript. eg.

cscript C:\\tools\\executePlink.vbs argument1 argument2