简体   繁体   English

如何在PowerShell二进制模块中捕获外部DLL的控制台输出?

[英]How to capture the console output of the external DLL in a PowerShell binary module?

I'm creating a PowerShell binary module, and it uses the third-party library (DLL), which outputs to the console. 我正在创建一个PowerShell二进制模块,它使用第三方库(DLL),它输出到控制台。 So, basically I'd like my binary module to output both its own messages and the console output of that DLL. 所以,基本上我希望我的二进制模块输出自己的消息和该DLL的控制台输出。

Is it possible? 可能吗?

So, let's say the third-party API does the following: 所以,让我们说第三方API执行以下操作:

public static void SomeMethod() {
  ...
  Console.Write("Extracting the file...");
  ...
}

The binary module calls it: 二进制模块调用它:

protected override void ProcessRecord() {
  ...
  this.WriteObject("Hello!");
  SomeClass.SomeMethod();
  this.WriteObject("Goodbye!");
}

The output I see is: 我看到的输出是:

Hello!
Goodbye!

What I'd like to see is: 我想看到的是:

Hello!
Extracting the file...
Goodbye!

Have a look at the System.Console.SetOut() method to temporarily set the current process's stdout to a text writer that you can read from. 查看System.Console.SetOut()方法,将当前进程的stdout临时设置为可以读取的文本编写器。 You'll use Console.OpenStandardOutput() to reset the stdout back to the default after calling the DLL. 在调用DLL之后,您将使用Console.OpenStandardOutput()将stdout重置为默认值。 Look at the example on the SetOut topic page. 查看SetOut主题页面上的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何捕获从Powershell运行的控制台exe的二进制标准输出? - How to capture binary stdout of a console exe run from Powershell? 如何在章鱼自定义PowerShell脚本中捕获控制台应用程序的输出? - How to capture console app output in Octopus custom PowerShell script? 如何将 Powershell 信息控制台输出捕获到变量? - How can I capture the Powershell informational console output to a variable? 如何将输出从 PowerShell 中的外部进程捕获到变量中? - How do I capture the output into a variable from an external process in PowerShell? Powershell:如何捕获PowerShell输出 - Powershell : How to capture powershell output 如何在模块内将控制台输出重定向到PowerShell输出? - How do I redirect Console Output to PowerShell Output within a module? 如何从 PowerShell 的外部命令输出中获取原始二进制数据? - How to get original binary data from external command output in PowerShell? 从Powershell中的外部DLL重定向输出 - redirecting output from an external dll in powershell 如何在Powershell控制台上捕获svn身份验证提示 - How to capture the svn authentication prompt on powershell console 如何在 PowerShell 中捕获外部命令进度? - How to capture external command progress in PowerShell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM