【问题标题】:PowerShell only captures certain output when invoked with output redirectionPowerShell 仅在使用输出重定向调用时捕获特定输出
【发布时间】:2022-11-30 13:56:20
【问题描述】:

accepted answer for How To Capture Output from Non-elevated Process Run from Elevated Powershell 仅包括当 BAT 文件调用带输出重定向的 powershell (>dummy.txt) 时 git config 的输出。无论是否应用重定向,都会捕获所有其他输出。为什么?有没有办法在不写入虚拟文件的情况下捕获此输出?

【问题讨论】:

    标签: powershell stdout


    【解决方案1】:

    runas.exe 命令总是在新控制台窗口,从调用者的角度来看是异步的,并产生输出在来电者的窗户。

    因此,捕获通过 runas.exe 启动的进程的输出的唯一方法是使该进程本身捕获其输出,例如通过 > 重定向,假设该进程是(例如 cmd.exe 或 PowerShell)。

    【讨论】:

      猜你喜欢
      • 2010-10-18
      • 2022-01-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多