BOOL Network::Network_LAN_Check(void)
{
m_bNetworkLANStatus = FALSE;
FILE* stream = NULL;
FILE* wstream = NULL;
char buf[20];
char temp[1024];
memset(temp,'\0',sizeof(temp));
memset(buf,'\0',sizeof(buf));
stream = popen("ping -c3 192.168.0.1", "r"); //gateway
wstream = fopen("/Customer/Network_LAN_CHECK.txt", "w+"); //Create a file
fread(temp, sizeof(char), sizeof(temp), stream);
fwrite(temp, 1, sizeof(temp), wstream);
printf("\n temp is =%s\n",temp);
pclose(stream);
fclose(wstream);
}
这是我的程序代码。最后Network_LAN_CHECK.txt里面的结果是
PING 192.168.0.1 (192.168.0.1): 56 data bytes
但是实际ping 3次的话结果是:
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=50.0 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=10.0 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=10.0 ms
--- 192.168.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2010ms
rtt min/avg/max/mdev = 10.000/23.333/50.001/18.857 ms
请问为什么文件里面只存储了第一行的数据。但是当我将ping 192.168.0.1命令改成ls -l 却可以获取到多行的完整数据。
求高手指点迷津!高分悬赏