小编jzb*_*uno的帖子

使用Start-Process捕获标准输出和错误

Start-Process访问StandardErrorStandardOutput属性时,PowerShell 命令中是否存在错误?

如果我运行以下命令,我得不到输出:

$process = Start-Process -FilePath ping -ArgumentList localhost -NoNewWindow -PassThru -Wait
$process.StandardOutput
$process.StandardError
Run Code Online (Sandbox Code Playgroud)

但是,如果我将输出重定向到文件,我得到预期的结果:

$process = Start-Process -FilePath ping -ArgumentList localhost -NoNewWindow -PassThru -Wait -RedirectStandardOutput stdout.txt -RedirectStandardError stderr.txt
Run Code Online (Sandbox Code Playgroud)

powershell start-process

96
推荐指数
6
解决办法
15万
查看次数

标签 统计

powershell ×1

start-process ×1