Solved

Return value of program invoked with system()

Posted on 2003-11-04
2
229 Views
Last Modified: 2010-04-22
Hi,
I'm writing a program that listens for network connections on a certain port.
Every X minutes it has to run a certain program (a program that I have written myself).
I do not wish to use cron or anything like it.
I invoke the program with the "system()" function and it works.
The only thing that annoys me is that I can't get hold of the return value of my program.

If I write this in my second program:

int main(...)
{
     ...
     if(...)
         return 999;
     ...
     return 666;
}

I want to use the return value for status purposes, how do I do this?
I want to be able to write something like this in my server program:

int runProgram()
{
    ...
    //INVOKE PROGRAM HERE
    switch (returnvalue)
    {
        case 666:
            ...
    }
    ...
}

Is this possible with the system() command?
If not, what should I use?

Thanks in advance,

Nicolas
0
Comment
Question by:The_LowRider
2 Comments
 
LVL 5

Accepted Solution

by:
mtmike earned 250 total points
ID: 9680232
The system() command returns the exit code like wait() does:

status = system("...");
if (status >= 0) {
  exitcode = WEXITSTATUS(status);
}

The macro WEXITSTATUS is defined in <sys/wait.h>.

Note that exit codes must be small integers in the range 0-127.
0
 
LVL 1

Author Comment

by:The_LowRider
ID: 9680282
Exactly what I needed, thanks!
Works great!

Nicolas.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
need help to replace faulty disk using lv mirroring 18 166
what does daemon command do in linux 3 75
check failing on yum update 5 30
Identify Linux loader 67 178
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question