system() exit code

From: Stephen Morgan (nospam_at_nospam.com)
Date: 05/15/04

  • Next message: David A. Ferguson: "How to execute from remote NFS?"
    Date: Fri, 14 May 2004 18:18:03 -0500
    
    

    Hi all,

    This script, call it "st"

          #! /bin/sh
          exit 123

    exits with exit code of 123, as it should. However, this C code:

          int rc;
          rc = system("/root/yada/yada/st");
          printf("return code is: %d\n", rc);

    prints "return code is: 31488" which is 123 shifted left 8 bits. I've
    tried this with a few values and the 8-bit shift is consistent.

    Is this normal behavior for the system() function, and if so, is it
    documented somewhere? Before I commit to code that relies on this behavior,
    I'd like to know that it's reliable :-)

    Thanks for your help,

    Stephen Morgan


  • Next message: David A. Ferguson: "How to execute from remote NFS?"