2008年8月5日 星期二

Get Program Return Value in C/Bash Shell

在 C shell 裡以 $status 取得執行檔的回傳值 (Bash 則是 $?)

Example:
test.c:

#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
return strtol(argv[1], NULL, 10);
}


test.csh

#!/bin/csh
./a.out $1
set rev=$status
if ( $rev == '0' ) then
echo "a.out returns 0."
else
echo "a.out returns $rev."
endif

沒有留言: