aa.exe 代码
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("hello world:{0}",i);
System.Threading.Thread.Sleep(1000);
}
aa.exe 返回结果
hello world:1
hello world:2
hello world:3
hello world:4
hello world:5
Start-Process 调用 aa.exe 返回执行结果
$process=(Start-Process -FilePath C:\Users\Administrator\aa.exe -PassThru -RedirectStandardOutput C:\Users\Administrator\result.txt -WindowStyle Hidden)
#3秒超时
$process.WaitForExit(3000)
$process.Kill()
Get-Content C:\Users\Administrator\result.txt
#$process.ExitCode
#$process.HasExited
输出结果
False
hello world:1
hello world:2
hello world:3