Solved

Return value of program invoked with system()

Posted on 2003-11-04
2
228 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now