當我cmd的命令是是ping 127.0.0.1 -t的命令時候,pclose無法關閉,始侄訓傳0或者列印over字串
int execmd(char* cmd,char* result)
{
char buffer[128];
int i=0;
FILE* pipe = _popen(cmd, "r"); //打開,并執行命令
if (!pipe)
return 1; //回傳1表示運行失敗
while(!feof(pipe))
{
if(fgets(buffer, 128, pipe)) //將輸出到result中
{
strcat(result,buffer);
if(i<5)
{
i=i+1;
}
if(i>=5)
{
break;
}
}
}
_pclose(pipe); //關閉
printf("over\n");
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/52047.html
