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
相关产品推荐
相关产品推荐

