-
-
[原创]调用命令行,带超时时间
-
发表于: 2016-4-11 16:29 2529
-
# -*- coding: utf-8 -*-
from subprocess import Popen
import time
def PopenWithTimeout(cmd,timeout=3600):
proc = Popen(cmd, shell=False)
#print(proc.pid) #shell=True 的话,则proc.pid的pid为shell的pid
bFlag = True
while timeout>0:
if proc.poll()!=None:
bFlag = False
break
time.sleep(1)
timeout = timeout-1
if bFlag:
proc.kill()
cmd = 'nmap -v -O 192.168.1.1'
PopenWithTimeout(cmd,timeout=10)
from subprocess import Popen
import time
def PopenWithTimeout(cmd,timeout=3600):
proc = Popen(cmd, shell=False)
#print(proc.pid) #shell=True 的话,则proc.pid的pid为shell的pid
bFlag = True
while timeout>0:
if proc.poll()!=None:
bFlag = False
break
time.sleep(1)
timeout = timeout-1
if bFlag:
proc.kill()
cmd = 'nmap -v -O 192.168.1.1'
PopenWithTimeout(cmd,timeout=10)
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
赞赏
他的文章
看原图
赞赏
雪币:
留言: