一般有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;
}