python之subprocess
官網介紹:https://docs.python.org/3/library/subprocess.html
Popen(): [[email protected] scripts]# cat sub_popen.py #!/usr/bin/python #coding=utf8 import subprocess child = subprocess.Popen([‘ls‘,‘-l‘],shell=True) print(type(child)) print(‘parent‘) [[email protected] scripts]# python sub_popen.py <class ‘subprocess.Popen‘> parent stu_subprocess.py sub_popen.py 如果將不添加shell,使用默認的: [[email protected]
[[email protected] scripts]# cat test_subprocess.py #!/usr/bin/python #coding=utf8 def TestPopen(): import subprocess p = subprocess.Popen([‘ls‘,‘-l‘],shell=True) for i in range(5): print("other things") print(TestPopen()) [[email protected] scripts]# python test_subprocess.py other things other things other things other things other things None stu_subprocess.py sub_call.py sub_check_output.py sub_popen.py sub_run.py test_subprocess.py [[email protected]