程式語言 - GNU - C/C++ - popen



參考資訊:
https://man7.org/linux/man-pages/man3/popen.3.html

main.c

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    char buf[255] = {0};
    FILE *fd = popen("uname -r", "r");

    if (fd) {
        fgets(buf, sizeof(buf), fd);
        pclose(fd);

        printf("%s", buf);
    }
    return 0;
}

編譯、執行

$ gcc main.c -o main
$ ./main
    4.19.0-9-amd64