通过系统shell运行命令
项目描述
首先查看envoy。 envoy.run(command) 在返回输出之前等待完成,这在包装长时间运行的工具时不是你需要的,当需要立即看到输出时,shellrun.run(command) 不会拦截输出 - 那是另一个命令。
>>> import shellrun >>> r = shellrun.run('uptime') 04:06:37 up 2 min, 1 user, load average: 0.20, 0.19, 0.08 >>> r.output >>> r.success True >>> r.retcode 0
要使用 envoy-风格的捕获输出,请使用 run_capture。 stdout 和 stderr 被合并,因为这是用户所看到的
>>> r = shellrun.run_capture('uptime') >>> r.output ' 04:07:16 up 2 min, 1 user, load average: 0.11, 0.17, 0.08\n' >>> r.success True >>> r.retcode 0
结果对象的快速比较
envoy.Response |
shellrun.Result |
---|---|
.command |
.command |
.status_code |
.retcode |
.success |
|
.output |
|
.std_out |
|
.std_err |
关于 .success 的使用示例
from shellrun import run_capture r = run_capture('ls -la') if r.success: print(r.output) else: print("Error: '%s' exit code %s" % (r.command, r.retcode)) print(" ...") # print last three lines of output for line in r.output.splitlines()[-3:]: print(" %s" % line)
项目详情
关闭
shellrun-3.1.zip的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b05503518f2d3d07d605a4be094b48ad9fbbaa5ff8263255b946f9624e2d5c47 |
|
MD5 | 4503feb20f74925d6912e95611783bb7 |
|
BLAKE2b-256 | 9179716905a6f94044a4ef5a4c1a894d83edeed1250edd693997e1296b0e38b9 |