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.

phuclv
  • 37,963
  • 15
  • 156
  • 475

1 Answers1

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775