python ping命令 封装前后运行结果不一致
python ping命令 打包前后运行结果不一致
这是打包前运行的:

这是打包后运行的情况
------解决思路----------------------
我试了一下, 一切正常, 几个ip地址, 有能接通的, 有不能的, 结果都对, 而且都是0或1.
环境: python27 + xp + py2exe 0.6.9.
------解决思路----------------------
按顶楼图2,打包的执行文件也叫ping,改个名字吧...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
def pingtest():
cmd="cmd.exe"
ips=""
begin=1
end=5
print(u"--------正在测试中请等待--------")
while begin<end:
p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
p.stdin.write("ping 192.168.1."+str(begin)+"\n")
p.stdin.close()
p.wait()
out = p.stdout.read()
#!print "execution result: %s"%p.stdout.read()
if u"请求超时" in out.decode("GBK"):
print "192.168.1."+str(begin)+u":连接异常"
else:
print "192.168.1."+str(begin)+u":连接正常"
begin=begin+1
raw_input("Press Enter to continue: ")
if __name__=="__main__":
pingtest()
这是打包前运行的:
这是打包后运行的情况
------解决思路----------------------
我试了一下, 一切正常, 几个ip地址, 有能接通的, 有不能的, 结果都对, 而且都是0或1.
环境: python27 + xp + py2exe 0.6.9.
------解决思路----------------------
按顶楼图2,打包的执行文件也叫ping,改个名字吧...