2016-01-16 110 views
-5

我在python 2.7中編程在kali linux我想在我的腳本中運行這個命令「airdump-ng」,但命令一直運行直到ctrl + c被按下,這在終端中是好的,但是在python中,當我按ctrl + c它退出整個腳本不只是一個命令,請幫助我這個我似乎無法弄清楚。Python運行命令,直到按下按鈕

+0

你需要捕捉鍵盤中斷 –

+1

'除了KeyboardInterrupt' –

+2

你爲什麼要標記「kali-linux」? – birdoftheday

回答

0

你可以這樣做:當你運行這個,然後按Ctrl-C

try: 
    while True: 
    print "running..." 
except KeyboardInterrupt: 
    print 'Ctrl-C was pressed' 

print 'one more line' 

,你會得到:

running... 
running... 
running... 
running... 
Ctrl-C was pressed 
one more line