博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux 使用system不安全,有时触发,有时不触发,替代函数如下
阅读量:4179 次
发布时间:2019-05-26

本文共 739 字,大约阅读时间需要 2 分钟。

int my_system(const char * cmd){    FILE * fp;    int res = 0;    char buf[1024] = {0};    if (cmd == NULL)    {        printf("my_system cmd is NULL!\n");        return -1;    }    if ((fp = popen(cmd, "r") ) == NULL)    {        perror("popen\n");        printf("popen error: %s/n", strerror(errno));        return -1;    }    else    {        while(fgets(buf, sizeof(buf), fp))        {            printf("%s", buf);        }        if ( (res = pclose(fp)) == -1)        {            printf("close popen file pointer fp error!\n");            return res;        }        else if (res == 0)        {            return res;        }        else        {            printf("pclose res is :%d\n", res);            return res;        }    }}

 

转载地址:http://czmai.baihongyu.com/

你可能感兴趣的文章
485. Max Consecutive Ones(数组)
查看>>
287. Find the Duplicate Number(数组)
查看>>
Linux内核-------同步机制(二)
查看>>
面试题31-------连续子数组的最大和(数组)
查看>>
epoll 实现Chat
查看>>
21. Merge Two Sorted Lists(链表)
查看>>
2. Add Two Numbers(链表)
查看>>
637. Average of Levels in Binary Tree(Tree)
查看>>
226. Invert Binary Tree(Tree)
查看>>
328. Odd Even Linked List(链表)
查看>>
617. Merge Two Binary Trees(Tree)
查看>>
700. Search in a Binary Search Tree(Tree)
查看>>
515. Find Largest Value in Each Tree Row(Tree)
查看>>
897. Increasing Order Search Tree(Tree)
查看>>
199. Binary Tree Right Side View(Tree)
查看>>
230. Kth Smallest Element in a BST(Tree)
查看>>
求字符串的最长回文串-----Manacher's Algorithm 马拉车算法
查看>>
回溯法常用的解题模板和常见题型
查看>>
深入分析Java I/O 的工作机制
查看>>
动态规划的套路----左神
查看>>