Как получить статус команды, выполняемой system ()

Я использую один системный вызов в моем коде c

#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);
}

, в моей текущей папке нет файла test12.out. Теперь вывод:

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

Вот моя команда оболочки не удалась, но как я могу узнать это в моем коде c?

Изменить:

Итак, могу я сделать это

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));
}
5
задан mulg0r 27 June 2018 в 16:06
поделиться