导语:
本文主要介绍了关于如何调用python中的shell脚本?的相关知识,包括python调取shell脚本,以及python控制shell命令这些编程知识,希望对大家有参考作用。
我相信每个人都应该对这方面有很好的了解。小编在前几期一直在教大家相关内容。我不知道我现在是否向你提及它。脑海中会不会有些印象?或者,大家能不能完成我们文章给小编的问题呢?至少你心里应该知道怎么调用一些脚本,然后根据自己的想象,阅读下面小编给出的内容,组合优化
~
1.
python调用shell方法os.system()
#!/usr/local/bin/python3.7
import time
import os
count = 0
n = os.system('sh b.sh')
while True:
count = count + 1
if count == 8:
print('this count is:',count)
break
else:
time.sleep(1)
print('this count is:',count)
print('Good Bye')
shell脚本如下:
#!/bin/sh
echo "hello world"
运行结果:
[python@master2 while]$ python a.py
hello world
this count is: 1
this count is: 2
this count is: 3
this count is: 4
this count is: 5
this count is: 6
this count is: 7
this count is: 8
Good Bye
2.
python调用shell方法os.popen()
#!/usr/local/bin/python3.7
import time
import os
count = 0
n = os.system('sh b.sh')
while True:
count = count + 1
if count == 8:
print('this count is:',count)
break
else:
time.sleep(1)
print('this count is:',count)
print('Good Bye')
运行结果:
[python@master2 while]$ python a.py
<os._wrap_close object at 0x7f7f89377940>
['hello world\n']
this count is: 1
this count is: 2
this count is: 3
this count is: 4
this count is: 5
this count is: 6
this count is: 7
this count is: 8
Good Bye
好吧,我们看看和通常的调用方式有什么不同?大概可以看出,大约
python调用脚本时候,大致都是这样子的吧,那大家如果遇到类似问题,可以举一反三学习哦~
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ python中字符串的用途是什么11/13
- ♥ python如何导入xls文件?11/17
- ♥ 如何在python中输入pi08/27
- ♥ python是如何实现继承的12/15
- ♥ 实例讲解join方法的使用12/02
- ♥ 零基础学习python读什么书11/12
内容反馈