zoukankan      html  css  js  c++  java
  • system替代函数

    // 使用popen代替system函数
    int my_system(const char * cmd) 
    { 
        FILE * fp; 
        int res;if (cmd == NULL) { 
            printf("my_system cmd is NULL!
    ");
            return -1;
        } 
    
        if ((fp = popen(cmd, "r") ) == NULL) { 
            perror("popen");
            printf("popen error: %s/n", strerror(errno)); 
            return -1; 
        } 
    
        if ((res = pclose(fp)) == -1) { 
            printf("close popen file pointer fp error!
    "); 
         return res;
        } else if (res == 0) {
            return res;
        } 
        // printf("popen res is :%d
    ", res); 

      return res; }
    // 将SIGCHLD设置为SIG_DFL处理方式,这种写法可能也存在问题,能不用还是别用了。
    int
    my_system(const char *cmd_line) { int ret = 0; sighandler_t old_handler; old_handler = signal(SIGCHLD, SIG_DFL); ret = system(cmd_line); signal(SIGCHLD, old_handler); return ret; }
  • 相关阅读:
    QTableWidget控件总结<一>
    软件工程概论9
    软件工程概论8
    软件工程概论7
    软件工程概论6
    软件工程概论5
    软件工程概论4
    软件工程概论3
    软件工程概论2
    安装gocode教程
  • 原文地址:https://www.cnblogs.com/coolYuan/p/14362399.html
Copyright © 2011-2022 走看看