Hey there,
I was looking at the rez code to have a reference for interacting with power-shell from Python.
At some point I copied this snippet of code which allow to catch the lastexit code:
|
executor.command( |
|
"if ((Test-Path variable:LASTEXITCODE) -and $LASTEXITCODE) {\n" |
|
" exit $LASTEXITCODE\n" |
|
"}\n" |
|
"if (! $?) {\n" |
|
" exit 1\n" |
|
"}" |
|
) |
However on my side it was not working as expected. For example, if you call a command that don't exist before it, the code behave as it was successfull.
From what I found it seems that it's become in that case we should rely on $?, however at the time of inspection, it has already been overwritten by the Test-Path command we call just before. So it's always True.
I manage to fix it by storing it's value in a variable before calling Test-Path
$_op_success = $?
if ((Test-Path variable:LASTEXITCODE) -and $LASTEXITCODE) {
exit $LASTEXITCODE
}
if (! $_op_success) {
exit 1
}
Keep in mind that none of this was tested with rez so I might be mistaking.
Liam.
Hey there,
I was looking at the rez code to have a reference for interacting with power-shell from Python.
At some point I copied this snippet of code which allow to catch the lastexit code:
rez/src/rezplugins/shell/_utils/powershell_base.py
Lines 163 to 170 in 78e2623
However on my side it was not working as expected. For example, if you call a command that don't exist before it, the code behave as it was successfull.
From what I found it seems that it's become in that case we should rely on
$?, however at the time of inspection, it has already been overwritten by theTest-Pathcommand we call just before. So it's alwaysTrue.I manage to fix it by storing it's value in a variable before calling
Test-PathKeep in mind that none of this was tested with rez so I might be mistaking.
Liam.