LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2005, 03:14 PM   #1
Yoko
LQ Newbie
 
Registered: Oct 2004
Posts: 24

Rep: Reputation: 15
Question get exit status from a C-program in Bash


In Bash I can get the exit status from commands, functions and scripts (with $?). But for some reasons I can't get the exit status from my own C-programs (I get always the same status, even if I exit with another value). Do I need to compile my C-programs with certain options? What am I doing wrong? Or what can I do?
 
Old 07-12-2005, 04:33 PM   #2
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
Have you just tried compiling a simple program? i.e. does this work:

C Code
Code:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
printf("Hello, world!\n");

  if( !strcmp( argv[1], "Success" ) )
     return 0;
  else
     return 1;
}
Bash Script
Code:
#!/bin/sh
./testc Success
echo "Return status was: " $?

./testc fail
echo "Return status was: " $?
My output was
Code:
Hello, world!
Return status was:  0
Hello, world!
Return status was:  1

Last edited by leonscape; 07-12-2005 at 04:35 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Webmin Server Status + Bash program to bring Apache up xbaez Programming 2 11-14-2005 07:57 AM
> Ftp With Exit Status, Ftp with exit status vwvr9 Linux - General 4 02-23-2005 02:53 AM
exit status naflan Programming 2 10-22-2004 12:22 PM
pppd exit status 1 wolfe2554 Linux - Networking 2 04-14-2004 12:15 AM
Trapping an exit status chrisk5527 Linux - General 3 09-12-2003 09:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration