ShellPy Python和Shell交互工具 项目简介
ShellPy 是一款Python和Shell的交互工具。一般来说,我们会通过Subprocess、Popen或者Command模块执行一条Shell命令或脚本,然后通过返回的标准输出和错误输出来得到结果,这个可行但不直观。ShellPy直观的解决了这一问题。shellpy的主体是Python,总体的编码和Python是一样的,想要嵌入Shell命令的时候,在命令前面加一个 ` (Tab上面那个键,一个右点号)。例如`ls -l`或者`ls -l也支持多行命令echo test > test.txt
cat test.txt长命令`echo This is \
a very long \
line也可以把返回结果赋值给一个变量result = `ls -l输出一个命令的返回码result = `ls -l
print result.returncode获取标准输入输出文本result = `ls -l
result_text = result.stdout
result_error = result.stderr逐行遍历文本result = `ls -l
for line in result:
print line.upper()
cat test.txt长命令`echo This is \
a very long \
line也可以把返回结果赋值给一个变量result = `ls -l输出一个命令的返回码result = `ls -l
print result.returncode获取标准输入输出文本result = `ls -l
result_text = result.stdout
result_error = result.stderr逐行遍历文本result = `ls -l
for line in result:
print line.upper()