Ê×Ò³ Ê«´Ê ×Öµä °å±¨ ¾ä×Ó ÃûÑÔ ÓÑ´ð ÀøÖ¾ ѧУ ÍøÕ¾µØͼ
µ±Ç°Î»ÖÃ: Ê×Ò³ > ½Ì³ÌƵµÀ > ²Ù×÷ϵͳ > UNIXLINUX >

linux ʧȥϵͳʱ¼ä

2013-03-10 
linux µÃµ½ÏµÍ³Ê±¼äÿÌì×ܽáÒ»µãµã£¬³É³¤Ò»µãµã~~1.Í·Îļþ#include ctimevoid executeCMD(const char *cm

linux µÃµ½ÏµÍ³Ê±¼ä

ÿÌì×ܽáÒ»µãµã£¬³É³¤Ò»µãµã~~

1.Í·Îļþ

#include <ctime>
void executeCMD(const char *cmd, char *result){    char buf_ps[1024];    char ps[1024]={0};    FILE *ptr;    strcpy(ps, cmd);    if((ptr=popen(ps, "r"))!=NULL)    {        while(fgets(buf_ps, 1024, ptr)!=NULL)        {           strcat(result, buf_ps);           if(strlen(result)>1024)               break;        }        pclose(ptr);        ptr = NULL;    }    else    {        printf("popen %s error\n", ps);    }}



ÈȵãÅÅÐÐ