subwrap-子流程的简单包装
subwrap的Python项目详细描述
这是stdlib子进程模块之上的一个非常薄的层。很简单 在我的许多项目中需要一些方便的功能。
完整的文档可以稍后提供,但如果您真的需要 使用子流程要容易得多,我会亲自尝试特使。然而,在这个 时间使者的开发似乎有点太早,所以我创建了 拥有很薄的一层来满足我目前的需要。
如果您想要更高的愿望,请查看特使。
示例
简单示例:
import subwrap response = subwrap.run(['echo', 'hello']) # Display hello print response.std_out
默认子包抛出一个^ {TT1}$,如果正在退出的命令退出 不是零的代码。捕捉默认命令错误:
import subwrap try: response = subwrap.run(['false']) except subwrap.CommandError, e: #this is the response, you can do what you want here response = e.response
不过,这并不总是有用的。可以使用子包运行自己的自定义退出 每个子进程的句柄。只需执行以下操作:
import subwrap def my_exit_handle(response): if response.return_code == 0: print "HAPPY DAY!" else: print "Not as happy" # The next line will output "Not as happy" to stdout response = subwrap.run(['false'], exit_handle=my_exit_handle)
许可证
麻省理工学院许可证