这是我的代码:
t5_send_notification
当我运行它时,我得到以下输出:
def ping_host(self, hostname, ping_cmd='/usr/bin/ping', count=1, timeout=400):
cmd = [ping_cmd, '-c%s' % count, '-W%s' % timeout, hostname]
(output, error) = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True).communicate()
print ' '.join( cmd )
print output, error
我认为我对第一个参数/usr/bin/ping -c1 -W400 tools-dev1.example.com
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
[-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
[-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
[-l preload] [-m mark] [-M pmtudisc_option]
[-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
[-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
[-W timeout] destination
做错了,我正在传递给cmd
,但是我不知道是什么。如果我将Popen()
粘贴到命令行,则效果很好。