programing

PowerShell의 $?와 $LastExitCode의 차이

elecom 2023. 4. 18. 21:44
반응형

PowerShell의 $?와 $LastExitCode의 차이

PowerShell의 경우,$?그리고.$LastExitCode?

자동변수에 대해 읽었는데, 다음과 같이 적혀 있더군요.

$? Contains the execution status of the last operation. It contains TRUE if the last operation succeeded and FALSE if it failed.

$LastExitCode Contains the exit code of the last Windows-based program that was run.

정의상$?성공과 실패가 무엇을 의미하는지 설명해주지 않는다.


라고 생각했기 때문에 묻습니다.$?$LastExitCode가 0인 경우에만 해당되지만, $LastExitCode=0이지만 $라는 놀라운 반론을 발견했습니다.=PowerShell에서 거짓입니다. stderr을 stdout으로 리디렉션하면 NativeCommandError가 발생합니다.

$LastExitCode는 네이티브 어플리케이션의 리턴 코드입니다. $?그냥 돌려줘True또는False마지막 명령어(native 또는 native)가 오류 없이 종료되었는지 여부에 따라 달라집니다.

cmdlet 장애는 보통 예외를 의미하지만 네이티브 애플리케이션의 경우 종료 코드가 0이 아닙니다.

PS> cmd /c "exit 5"
PS> $?
False
PS> cmd /c "exit 0"
PS> $?
True

+를 사용하여 Ccmdlet을 취소해도 실패로 간주됩니다. 네이티브 애플리케이션의 경우 설정한 종료 코드에 따라 달라집니다.

언급URL : https://stackoverflow.com/questions/10666035/difference-between-and-lastexitcode-in-powershell

반응형