Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:28:52+00:00 2026-05-28T07:28:52+00:00

I am using one system call in my c code #include <sys/stat.h> #include <stdio.h>

  • 0

I am using one system call in my c code

#include <sys/stat.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
    int a = system("./test12.out");  //here if i give any wrong command
    system("echo $?")
    printf("system return is %d",a);
}

there isn’t any test12.out file in my current folder. Now output is

sh: ./test12.out: No such file or directory
0
system return is 32512

Here is my shell command failed but how can I know that in my c code?

Edit:

So, can I do this

int main(int argc, char *argv[])
{
    int a = system("dftg");

    if(a == -1)
        printf("some error has occured in that shell command");
    else if (WEXITSTATUS(a) == 127)
        printf("That shell command is not found");
    else
        printf("system call return succesfull with  %d",WEXITSTATUS(a));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:28:52+00:00Added an answer on May 28, 2026 at 7:28 am

    If a == -1, the call has failed. Otherwise, the exit code is WEXITSTATUS(a).

    To quote man 3 system:

    RETURN VALUE
           The value returned is -1 on  error  (e.g.   fork(2)  failed),  and  the
           return  status  of the command otherwise.  This latter return status is
           in the format specified in wait(2).  Thus, the exit code of the command
           will  be  WEXITSTATUS(status).   In case /bin/sh could not be executed,
           the exit status will be that of a command that does exit(127).
    
           If the value of command is NULL, system() returns non-zero if the shell
           is available, and zero if not.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: #include<stdio.h> #include<stdlib.h> #include<sys/stat.h> #include<sys/types.h> #include<fcntl.h> #include<unistd.h> #include<errno.h> int main(int argc,char
We're about to make data transformation from one system to another using SSIS. We
I am using System.Timers.Timer class in one of the classes in my application. I
Im using System.Windows.MessageBox.Show() to display a dialog to the user. One overload lets me
How much should one DataSet represent? Using the example of an ordering system: While
I'm starting up a new embedded system design using FreeRTOS. My last one used
I am using using os.system call from python to run jar file. The jar
I am using webservice to call method in businesslogics(one class written in vb).I am
Even 2 decades ago, it was possible to call code written in one language
i'm trying to apply some module system on my web, using get and include,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.