Solved

Return value of program invoked with system()

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

12 Experts available now in Live!

Get 1:1 Help Now