You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Github Action中PowerShell运行Windows可执行文件无输出如何解决?

解决GitHub Actions中Windows可执行文件无输出的问题

以下是几种捕获Windows可执行文件输出的方法,可逐一尝试:

  • 重定向所有输出流到控制台
    部分可执行文件会将输出写入标准错误流(stderr),而PowerShell默认仅显示标准输出流(stdout)。使用*>&1可以将所有输出流合并到标准输出,确保GitHub Actions能捕获到:

    name: Check exe
    run: |
      .\file.exe *>&1
    
  • 捕获输出到变量后打印
    把可执行文件的输出存入变量,再显式打印变量内容,确保无遗漏:

    name: Check exe
    run: |
      $exeOutput = .\file.exe *>&1
      Write-Output $exeOutput
    
  • 通过Start-Process捕获输出
    针对非控制台程序或需要特殊运行方式的可执行文件,使用Start-Process指定输出重定向:

    name: Check exe
    run: |
      # 运行程序并将输出写入文件
      Start-Process -FilePath .\file.exe -NoNewWindow -Wait `
        -RedirectStandardOutput "stdout.txt" `
        -RedirectStandardError "stderr.txt"
      # 打印输出内容
      Get-Content "stdout.txt"
      Get-Content "stderr.txt"
    
  • 检查权限并以管理员身份运行
    如果可执行文件需要管理员权限,可通过Start-Process提升权限并捕获输出:

    name: Check exe
    run: |
      Start-Process -FilePath .\file.exe -Verb RunAs -Wait -NoNewWindow `
        -RedirectStandardOutput "admin_stdout.txt" `
        -RedirectStandardError "admin_stderr.txt"
      Get-Content "admin_stdout.txt"
      Get-Content "admin_stderr.txt"
    

内容的提问来源于stack exchange,提问作者Spicy sauce

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 14:47:11