执行脚本:若Popen,不需要等待run_networked 的指令结束;而使用run需要等待run_networked完成
import subprocess
import time
def run_command(n = 10, time_interval = 1):
i = 0
ss = []
subprocess.Popen('./run_networked.sh') #no wait time
while i < n:
print('ss-ing ........')
ss.append(subprocess.run(['ss', '( dport = :8080 or sport = :8080 )' ], stdout=subprocess.PIPE).stdout.decode('utf-8'))
time.sleep(time_interval)
i += 1
return ss
run_command()