Obtaining ExitCode using Start-Process and WaitForExit instead of -Wait

后端 未结 6 1025
一生所求
一生所求 2020-11-29 01:29

I\'m trying to run a program from PowerShell, wait for the exit, then get access to the ExitCode, but I am not having much luck. I don\'t want to use -Wait with

6条回答
  •  旧巷少年郎
    2020-11-29 02:10

    Here's a variation on this theme. I want to uninstall Cisco Amp, wait, and get the exit code. But the uninstall program starts a second program called "un_a" and exits. With this code, I can wait for un_a to finish and get the exit code of it, which is 3010 for "needs reboot". This is actually inside a .bat file.

    If you've ever wanted to uninstall folding@home, it works in a similar way.

    rem uninstall cisco amp, probably needs a reboot after
    
    rem runs Un_A.exe and exits
    
    rem start /wait isn't useful
    "c:\program files\Cisco\AMP\6.2.19\uninstall.exe" /S
    
    powershell while (! ($proc = get-process Un_A -ea 0)) { sleep 1 }; $handle = $proc.handle; 'waiting'; wait-process Un_A; exit $proc.exitcode
    

提交回复
热议问题