-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sunday 26 January 2003 10:24 pm, David Kramer wrote: > On Sunday 26 January 2003 01:12 pm, exits funnel wrote: [snip] > > When I compile this and run it from bash I see "Return > > Value: 256" at stdout as I'd expect. However, I then > > immediately 'echo $?' and bash spits back '0' rather > > than '256.' Is this correct? Shouldn't $? hold the > > return value of the last program run from bash (ie, my > > c program?) Thanks in advance for any replies. > > Your problem is that you need to call exit() and not return() from > main() to set the exit value.
Either appears to work, the problem is that the return code is too large. The same results occur with both exit() and return() $ cat return.cpp #include <iostream> int main( ) { int return_value = system("ls -l /fff"); std::cout << "\n Return Value: " << return_value << "\n"; exit return_value; } Results in: $ ./return1 ls: /fff: No such file or directory Return Value: 256 [mfratoni@paradox mfratoni]$ echo $? 0 While reducing the exit value works: #include <iostream> int main( ) { int return_value = system("ls -l /fff"); std::cout << "\n Return Value: " << return_value << "\n"; exit (return_value - 1); } $ ./return1 ls: /fff: No such file or directory Return Value: 256 [mfratoni@paradox mfratoni]$ echo $? 255 - -- - -Michael pgp key: http://www.tuxfan.homeip.net:8080/gpgkey.txt Red Hat Linux 7.{2,3}|8.0 in 8M of RAM: http://www.rule-project.org/ - -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE+NLLnn/07WoAb/SsRAhijAJ9JolmRTdRJXI7B4wK6rf/CORsIRwCgruyd bsE8wv44RTLINycMQOI7dA0= =Swga -----END PGP SIGNATURE----- -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list