Jan 25, 2008

How to see the return value of the last executed command

We obtain the status of the last executed command by executing the following commands

Windows

echo %ERRORLEVEL%

Linux

echo $?

/** retvaluetest.c **/
int main(){
int retval = 10;
printf("\n Return Value is = %d", retval);
return retval;
}

Windows
D:\CPROBL~1>retvaluetest.exe

Return Value = 10
D:\CPROBL~1>retvaluetest.exe

Return Value = 10

Unix
[root@root]# gcc retvaluetest.c
[root@root]# ./a.out

Return Value = 10
[root@root]# echo $?
10

No comments :

Post a Comment