这Start-Process是出于某种原因而设计的。这是一种无需发送到文件即可获取的方法:
$pinfo = New-Object System.Diagnostics.ProcessStartInfo$pinfo.FileName = "ping.exe"$pinfo.RedirectStandardError = $true$pinfo.RedirectStandardOutput = $true$pinfo.UseShellExecute = $false$pinfo.Arguments = "localhost"$p = New-Object System.Diagnostics.Process$p.StartInfo = $pinfo$p.Start() | Out-Null$p.WaitForExit()$stdout = $p.StandardOutput.ReadToEnd()$stderr = $p.StandardError.ReadToEnd()Write-Host "stdout: $stdout"Write-Host "stderr: $stderr"Write-Host "exit pre: " + $p.ExitCode
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)