
用的python 3.3 不知道问题在哪
importsubprocesscmd="cmd.exe"begin=1end=20whilebegin<end:p=subprocess.Popen(cmd,shell...
import subprocess
cmd="cmd.exe"
begin=1
end=20
while begin<end:
p=subprocess.Popen(cmd,shell=True,stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p.stdin.write('ping 192.168.1.'+(str(begin))+'\n')
p.stdin.close()
p.wait()
print("execution result:%s"%p.stdout.read())
提示 str 不支持interface
问题就是运行不了 提示str
谁告诉我3.3中的 str()怎么用
这是照书抄的 我是初学者 初学python 展开
cmd="cmd.exe"
begin=1
end=20
while begin<end:
p=subprocess.Popen(cmd,shell=True,stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p.stdin.write('ping 192.168.1.'+(str(begin))+'\n')
p.stdin.close()
p.wait()
print("execution result:%s"%p.stdout.read())
提示 str 不支持interface
问题就是运行不了 提示str
谁告诉我3.3中的 str()怎么用
这是照书抄的 我是初学者 初学python 展开
3个回答
展开全部
对照你的:
想要回答你问题,但是不知道你的问题在哪
提示:
我知道Python 3.x中,str有很多改动。
=========
那你早说啊,汗。
自己去看就行了:
【整理】Python中字符编码的总结和对比:Python 2.x的str和unicode vs Python 3.x的bytes和str
其他更多的,你容易犯的问题,自己去看:
【教程】Python开发入门详解
(此处不给贴地址,请自己用google搜标题,即可找到帖子地址)
想要回答你问题,但是不知道你的问题在哪
提示:
我知道Python 3.x中,str有很多改动。
=========
那你早说啊,汗。
自己去看就行了:
【整理】Python中字符编码的总结和对比:Python 2.x的str和unicode vs Python 3.x的bytes和str
其他更多的,你容易犯的问题,自己去看:
【教程】Python开发入门详解
(此处不给贴地址,请自己用google搜标题,即可找到帖子地址)
展开全部
类似的功能我做过。用管道作为通讯方法不是很好。有可能会阻塞,另外它还有一个锁与缓冲的问题。通常我们都是直接写在参数里的。而不是再后来write到 PIPE。 所以你直接cmd.exe /c ping就可以了。
另外管道在LINUX下还是比较好用的。但是在WINDOWS下似乎有些问题。
至于你的那个提示str不支持interface。我看不懂。我试了一下。完整的提示是
>>>
Traceback (most recent call last):
File "D:/john/desktop/p1.py", line 9, in <module>
p.stdin.write('ping 192.168.1.'+(str(begin))+'\n')
TypeError: 'str' does not support the buffer interface
这可能是你的使用方法的问题。我印象中我也没有这么用过,而是用communicate。去查一下帮助,有下面的提示。
Warning
Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process
另外管道在LINUX下还是比较好用的。但是在WINDOWS下似乎有些问题。
至于你的那个提示str不支持interface。我看不懂。我试了一下。完整的提示是
>>>
Traceback (most recent call last):
File "D:/john/desktop/p1.py", line 9, in <module>
p.stdin.write('ping 192.168.1.'+(str(begin))+'\n')
TypeError: 'str' does not support the buffer interface
这可能是你的使用方法的问题。我印象中我也没有这么用过,而是用communicate。去查一下帮助,有下面的提示。
Warning
Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
p.stdin.write('ping 192.168.1.'+(str(begin))+'\n') 修改成
strstring='ping 192.168.253.'+str(begin)+'\n'
p.stdin.write(strstring.encode())
strstring='ping 192.168.253.'+str(begin)+'\n'
p.stdin.write(strstring.encode())
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询