Sh.py: Using any shell command as Python func

2012-09-17 10:30:44 +08:00
 soulhacker
http://amoffat.github.com/sh/index.html

Samples:

# print ifconfig
from sh import ifconfig
print(ifconfig("wlan0"))

# checkout master branch
git(checkout="master")

# print the contents of this directory
print(ls("-l"))

# get the longest line of this file
longest_line = wc(__file__, "-L")
6980 次点击
所在节点    Python
10 条回复
shiweifu
2012-09-17 11:15:49 +08:00
赞!
for4
2012-09-17 11:54:47 +08:00
很酷啊!
cabinw
2012-09-17 12:05:02 +08:00
大赞!
fanzeyi
2012-09-17 12:53:47 +08:00
很棒=w=
RagnarokStack
2012-09-17 13:23:35 +08:00
Awesome!
yegle
2012-09-17 13:40:07 +08:00
好精彩!

有个问题,考虑到POSIX style和GNU style的不同,这个例子在Mac之类系统上执行可能有问题:

from sh import ls

ls = ls.bake("-la")
print(ls) # "/usr/bin/ls -la"

# resolves to "ls / -la"
print(ls("/"))

应该resolve成ls -la /
eric_q
2012-09-17 13:55:04 +08:00
一定程度上可以抛弃 subprocess 了
chaoswong189
2012-09-17 17:15:31 +08:00
cool work!!
很好用,咋早没想到写个这个出来……
离偷懒的程序员差得还很远啊
chuangbo
2012-09-17 21:00:56 +08:00
看完文档,真的是屌爆了,神器级别的
gastlygem
2012-09-18 13:56:57 +08:00
很有趣的项目,Windows支持在这里: http://pypi.python.org/pypi/pbs

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/47892

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX