在python中运行shell命令的更好方法。
shell的Python项目详细描述
“在python中运行shell命令的更好方法。”“
因为每次我使用subprocess时,我在 比实际执行我要完成的任务更具前瞻性。
完整的文档位于https://shell.readthedocs.org/en/latest/。
要求
- python 2.6+或python 3.3+
用法
如果只需要快速运行命令,可以使用shell快捷方式 功能:
>>> from shell import shell >>> ls = shell('ls') >>> for file in ls.output(): ... print file 'another.txt'
如果需要扩展行为,还可以使用Shell对象:
>>> from shell import Shell >>> sh = Shell(has_input=True) >>> cat = sh.run('cat -u') >>> cat.write('Hello, world!') >>> cat.output() ['Hello, world!']
如果您愿意,您甚至可以连络电话:
>>> from shell import shell >>> shell('cat -u', has_input=True).write('Hello, world!').output() ['Hello, world!']
安装
使用pip,只需运行:
pip install shell
许可证
新的BSD