如何将 Ruby 的 IO.popen 调用转换为 Python 的 subprocess.Popen 调用?
我已经阅读了文档,并且在 REPL 和 Google 中尝试了很多东西,但我一生都无法理解 subprocess.Popen 在 Python 中工作。
以下是我正在使用的一些 Ruby 代码:
IO.popen("some-process") do |io|
while(line = io.gets)
# do whatever with line
end
end
How do I translate this into Python using subprocess.Popen?
I've read the documentation and I've tried lots of things in the REPL, and Googled, but I can't for the life of me understand how subprocess.Popen works in Python.
Here is some Ruby code I am using:
IO.popen("some-process") do |io|
while(line = io.gets)
# do whatever with line
end
end
How do I translate this into Python using subprocess.Popen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是 Python 中 Ruby 代码最简单的“近亲”:
Probably the simplest "close relative" of your Ruby code in Python: