用的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
展开
 我来答
againinput4
2012-12-14 · TA获得超过2407个赞
知道大有可为答主
回答量:1446
采纳率:70%
帮助的人:676万
展开全部
对照你的:
想要回答你问题,但是不知道你的问题在哪

提示:
我知道Python 3.x中,str有很多改动。
=========

那你早说啊,汗。
自己去看就行了:
【整理】Python中字符编码的总结和对比:Python 2.x的str和unicode vs Python 3.x的bytes和str

其他更多的,你容易犯的问题,自己去看:
【教程】Python开发入门详解

(此处不给贴地址,请自己用google搜标题,即可找到帖子地址)
bdwisyou7d
2012-12-13 · TA获得超过1.3万个赞
知道大有可为答主
回答量:3775
采纳率:81%
帮助的人:1082万
展开全部
类似的功能我做过。用管道作为通讯方法不是很好。有可能会阻塞,另外它还有一个锁与缓冲的问题。通常我们都是直接写在参数里的。而不是再后来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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ch237158596
2013-10-16
知道答主
回答量:4
采纳率:100%
帮助的人:4.5万
展开全部
p.stdin.write('ping 192.168.1.'+(str(begin))+'\n') 修改成

strstring='ping 192.168.253.'+str(begin)+'\n'

p.stdin.write(strstring.encode())
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式