运行shell命令
runcmd的Python项目详细描述
安装
$ [sudo] pip install runcmd
类
class | ^{ |
---|---|
^{ | Process class |
函数
function | ^{ |
---|---|
^{ | run command and return Process object |
示例
>>>importruncmd>>>r=runcmd.run(["echo","hello world"])>>>r.code# exit status code0>>>r.out# stdout'hello world'>>>r.err# stderr''>>>r.pid# process pid1234
background=True
>>>r=runcmd.run(["sleep","5"],background=True)>>>whiler.running:# True if process is running and not "zombie process">>>print("running")
kill(signal=None)
-终止进程
>>>r.kill(-9)
exc()
-如果代码不是0
,则引发异常
>>>runcmd.run(["ls"]).exc()# code 0, ok>>>runcmd.run(["mkdir","/"]).exc()# code 1, raise OSError...OSError:exitedwithcode1mkdir:/:Isadirectory