1
这里是有问题的代码:为什么这个正则表达式不起作用?
import subprocess
import re
import os
p = subprocess.Popen(["nc -zv 8.8.8.8 53"], stdout=subprocess.PIPE, shell = True)
out, err = p.communicate()
regex = re.search("succeeded", out)
if not regex:
print ("test")
我希望它做的是打印出来的测试,如果正则表达式不匹配的netcat命令。现在我只是匹配“成功”,但是这就是我需要的,因为netcat的命令打印出:
Connection to 8.8.8.8 53 port [tcp/domain] succeeded!
的代码运行正常,但它时,它不应该相匹配?
工作很好,谢谢Padraic! – nillenilsson