royzs 发表于 2014-10-13 10:14

初学Python,看起来跟Java格式非常相似啊,执行报错

本帖最后由 royzs 于 2014-10-13 10:45 编辑

# cat test.py
#!/usr/bin/env python
import subprocess

cmd="cmd.exe"
begin=101
end=200
while begin<end:

    p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
                   stdin=subprocess.PIPE,
                   stderr=subprocess.PIPE)
    p.stdin.write("ping 192.168.8."+str(begin)+"\n")

    p.stdin.close()
    p.wait()

    print "execution result: %s"%p.stdout.read()执行的时候报错,不知道是哪里的问题

royzs 发表于 2014-10-13 10:16

本帖最后由 royzs 于 2014-10-13 10:16 编辑

# ./test.py
execution result:
……
……
……
execution result:
Traceback (most recent call last):
File "./test.py", line 12, in <module>
    p.stdin.write("ping 192.168.8."+str(begin)+"\n")
IOError: Broken pipe

royzs 发表于 2014-10-13 10:47

太粗心了,原来是Windows平台的,如果在Linux平台下应该怎么改一下测试用呢,求助

zongg 发表于 2014-10-13 17:36

菜鸟帮不上忙。
页: [1]
查看完整版本: 初学Python,看起来跟Java格式非常相似啊,执行报错