coc仓库--popen命令的封装

发布时间 2023-07-18 22:42:37作者: (⊃・ᴥ・)つ

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.函数解析

函数很简单。无须多言。