Python运行命令直到按下按钮

时间:2016-01-16 14:16:13

标签: python

我在kali linux的python 2.7中编程我想运行这个命令" airdump-ng"在我的脚本,但命令运行,直到ctrl + c被按下这在终端很好,但在python当我点击ctrl + c它退出整个脚本不只是一个命令请帮我这个我似乎不能弄明白。

1 个答案:

答案 0 :(得分:0)

你可以这样做:

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

print 'one more line'

运行此按钮并按Ctrl-C时,您将获得:

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