Solved

Return value of program invoked with system()

Posted on 2003-11-04
2
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

734 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