I am not a great powershell expert and I stumble on a problem that is undoubtedly trivial
When I run the following command in CMD (SAP related but it's not important)
.\sapcontrol.exe -nr 00 -prot PIPE -function GetProcessList
I get an exit code which may have different values depending on the state of the processes :
0 Last webmethod call successful
1 Last webmethod call failed, invalid parameter
2 StartWait, StopWait, WaitforStarted, WaitforStopped, RestartServiceWait timed out
3 GetProcessList succeeded, all processes running correctly
4 GetProcessList succeeded, all processes stopped
In powershell when i use
Start-Process or & cmd.exe / c my $LASTEXITCODE or $? always returns 0 (probably to tell me that the command has been executed ... but that's not what I want ...)
how to get the equivalent of EXITCODES in powershell ?
thanks in advance
$LASTEXITCODEto be populated, you need to invoke the executable directly, eg.& .\sapcontrol.exe .... If you're usingStart-Process, you'll have to check theExitCodeproperty on theProcessobject returned byStart-ProcessStart-Processinstead of running the exe file directly?