社区
脚本语言
帖子详情
请教个问题: os.popen4 在有些电脑上运行正常(批处理内容能显示出来),而在有此电脑上不正常。
oncsdn
2005-12-05 10:33:50
import os
f = os.popen4("dir")
l = f[1].readlines()
while l:
print l
l = f[1].readlines()
f[0].close()
f[1].close()
当然,实际中用的不是 "dir" 命令,而是一个批处理。
...全文
231
5
打赏
收藏
请教个问题: os.popen4 在有些电脑上运行正常(批处理内容能显示出来),而在有此电脑上不正常。
import os f = os.popen4("dir") l = f[1].readlines() while l: print l l = f[1].readlines() f[0].close() f[1].close() 当然,实际中用的不是 "dir" 命令,而是一个批处理。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
shhgs
2005-12-26
打赏
举报
回复
如果不用读写STDIN,STDOU的话可以用os.system
DIR> python <script_name> [arg ... ]
的意思是,如果你写了一个脚本叫abc.py,运行脚本的时候要 -x参数,那么你应该用
python abc.py -x
命令来启动脚本
你说的执行批处理的时候Python会突然关闭,我没碰到过,建议你使用高版本的Python,好像
python.org的主页上已经没有2.1的文档了。或许这里有bug也不一定。
oncsdn
2005-12-26
打赏
举报
回复
不知道怎么给分,不好意思 shhgs()
这个与最开始好象不一样了,过去是点“管理”就好了
oncsdn
2005-12-26
打赏
举报
回复
如果不用读写STDIN,STDOU的话可以用os.system
>>> 确却来说,我需要用 stdout 及 stderr
DIR> python <script_name> [arg ... ]
的意思是,如果你写了一个脚本叫abc.py,运行脚本的时候要 -x参数,那么你应该用
python abc.py -x
命令来启动脚本
>>> 懂了,3Q :)
你说的执行批处理的时候Python会突然关闭,我没碰到过,建议你使用高版本的Python,好像
python.org的主页上已经没有2.1的文档了。或许这里有bug也不一定。
>>> 我试了 2.4 版,一样的结果(会突然结束)
>>> 感谢您对我问题的答复
oncsdn
2005-12-16
打赏
举报
回复
第一,什么版本的Python?2.4引入了subprocess,不一样了
>>> 2.1 版
第二,哪个平台上的,Windows还是Unix
>>> windows xp
第三,很多时候,在Windows上,要用
DIR> python <script_name> [arg ... ]
来运行程序
>>> 不是太懂
>>> 我是先 os.chdir("批处理所在目录")
>>> 然后用 os.popen4("批处理")
>>> 执行的
>>> 你说的是在命令行状态吧,我是取当前目录然后拼出要执行的命令路径执行的
>>>
>>> 还有,有时执行批处理时, Python 会突然关闭(使用 os.popen4 ),也一直没搞清楚为>>>啥,最开始认为是批处理有向 stderr 输出的内容,所以使用 os.popen4 ,现象有所好转,>>>但没有完全去除
>>>
>>> 谢谢楼上的答复 :)
shhgs
2005-12-13
打赏
举报
回复
第一,什么版本的Python?2.4引入了subprocess,不一样了
第二,哪个平台上的,Windows还是Unix
第三,很多时候,在Windows上,要用
DIR> python <script_name> [arg ... ]
来运行程序
[leetcode] 215. Kth Largest Element in an Array 解题报告
题目链接:https://leetcode.com/problems/kth-largest-element-in-an-array/ Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth dis
[Leetcode] 215. Kth Largest Element in an Array 解题报告
题目: Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, r
Leetcode解题报告:215. Kth Largest Element in an Array
题目大意: Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2,
215. Kth Largest Element in an Array 【leetcode解题报告】
题目: Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, ...
【LeetCode】215. Kth Largest Element in an Array 解题报告(Python & C++)
【LeetCode】215. Kth Largest Element in an Array 解题报告 标签: LeetCode 题目地址:https://leetcode.com/problems/kth-largest-element-in-an-array/description/ 题目描述: Find the kth largest element in an unsort
脚本语言
37,739
社区成员
34,211
社区内容
发帖
与我相关
我的任务
脚本语言
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
复制链接
扫一扫
分享
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
试试用AI创作助手写篇文章吧
+ 用AI写文章