coc仓库--popen命令的封装

(⊃・ᴥ・)つ / 2023-07-19 / 原文

popen命令的封装

1.源码

int runShellNoReturn(const char *cmd, const char *mode)
{
    FILE *file = popen(cmd, mode);
    if (file == NULL)
    {
        return 1;
    }
    else
    {
        pclose(file);
        return 0;
    }
}

FILE *runShellAndReturn(const char *cmd, const char *mode)
{
    FILE *file = popen(cmd, mode);
    if (file == NULL)
    {
        return NULL;
    }
    else
    {
        return file;
    }
}

2.函数解析

函数很简单。无须多言。