标签:
一般有3种方法:1.exec函数 2.system函数 3. popen
int xpipe(char *cmdname, char *outbuf, int outlen) { int ret = 0; FILE *pf; pf = popen(cmdname, "r"); if( !pf ) return -1; if(outbuf) { ret = fread(outbuf, 1, outlen-1, pf); if(ret<=0) { pclose(pf); return ret; } while( outbuf[ret-1] == '\r' || outbuf[ret-1] == '\n' ) ret--; outbuf[ret] = 0; } pclose(pf); return ret; }
标签:
原文地址:http://blog.csdn.net/aa838260772/article/details/42676751