python脚本与shell脚本的相互调用
python脚本调用shell脚本:
存在的shell脚本(test_sh.sh):
find . -name 2.txt
在python脚本中调用test_sh.sh脚本
import os
os.system('./test_sh.sh')
当需要传参数到shell脚本中时
shell脚本test_sh.sh:
mv ${1} ${2}
python脚本(test.py)
import os
files = os.listdir(r'./')
for f in files:
os.system('./test_sh.sh' +' '+f + ' '+ '123.txt' )
在linux环境下执行python脚本, python test.py就能改名字了
shell调用python并且传参数
shell脚本(test_sh.sh)内容:
python ./test.py $"hello" $"world"
python 脚本(test.py)
import sys
def main(a, b):
print(a,b)
main(sys.argv[1], sys.argv[2])
在linux环境执行 sh test_sh.sh,就会输出 hello world
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)