該函數功能在stdio.h中有實現,調用很簡單。
如下源碼:
[cpp]
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
FILE *f;
char buf[80]={0};
f = _popen("ping.exe 127.0.0.1", "r");
if (NULL!=f)
{
while(fgets(buf, sizeof(buf), f)>0){
/*
* what you want...?
*
*/
printf("Pipe: %s", buf);
fflush(stdout);
}
}
_pclose(f);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
FILE *f;
char buf[80]={0};
f = _popen("ping.exe 127.0.0.1", "r");
if (NULL!=f)
{
while(fgets(buf, sizeof(buf), f)>0){
/*
* what you want...?
*
*/
printf("Pipe: %s", buf);
fflush(stdout);
}
}
_pclose(f);
return 0;
}
實際運行結果: