1

I created a simple test.c code:

int main()
{
    int a;
    return -1;
}

Compiling with: gcc -o test test.c

Later I executed it: .\test.exe

Is it possible to see the return value in the terminal? not a log file.

1 Answer 1

1

PowerShell reports the process exit code of the most recently executed console application in the automatic $LASTEXITCODE variable.

The related automatic $? variable is an abstract success indicator, reporting $true or $false, for all commands; in the case of console applications, a process exit code of 0 maps to $true, any other value to $false.

For reasons explained in this answer, it is better to use $LASTEXITCODE directly for console applications ($LASTEXITCODE -eq 0 to test for success) , because in PowerShell versions prior to 7.2, $? can yield false negatives.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.