python执行cmd命令,怎么让他执行类似Ctrl+C效果将其结束命令
1个回答
展开全部
python执行cmd命令,怎么让他执行Ctrl+C的效果结束命令?
我在用ping监控一个服务器的网络状态,我执行了ping命令后,他会一直这么ping下去,不停止,怎么让他在10秒后执行ctrl+c的效果
def re(cmd): while True:
os.system(cmd);re("ping 192.168.1.1 -t")
他会这样一直ping下去,想了半天也想不出怎么让他10秒后执行ctrl+c结束的执行效果,请教大神,怎么让他执行结束命令;
10秒后停止命令,类似执行ctrl+c的效果;
[root@jenkins xxxx]# time ping baidu.com -w 10s
PING baidu.com (220.181.57.217) 56(84) bytes of data.64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=1 ttl=52 time=4.07 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=2 ttl=52 time=26.9 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=3 ttl=52 time=6.78 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=4 ttl=52 time=12.9 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=5 ttl=52 time=3.86 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=6 ttl=52 time=3.30 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=7 ttl=52 time=5.63 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=8 ttl=52 time=11.2 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=9 ttl=52 time=4.30 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=10 ttl=52 time=4.17 ms
--- baidu.com ping statistics ---10 packets transmitted, 10 received, 0% packet loss, time 9013ms
rtt min/avg/max/mdev = 3.300/8.328/26.972/6.954 ms
real 0m10.006s
user 0m0.003s
sys 0m0.006s
不知道能不能满足你的需求
我在用ping监控一个服务器的网络状态,我执行了ping命令后,他会一直这么ping下去,不停止,怎么让他在10秒后执行ctrl+c的效果
def re(cmd): while True:
os.system(cmd);re("ping 192.168.1.1 -t")
他会这样一直ping下去,想了半天也想不出怎么让他10秒后执行ctrl+c结束的执行效果,请教大神,怎么让他执行结束命令;
10秒后停止命令,类似执行ctrl+c的效果;
[root@jenkins xxxx]# time ping baidu.com -w 10s
PING baidu.com (220.181.57.217) 56(84) bytes of data.64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=1 ttl=52 time=4.07 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=2 ttl=52 time=26.9 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=3 ttl=52 time=6.78 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=4 ttl=52 time=12.9 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=5 ttl=52 time=3.86 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=6 ttl=52 time=3.30 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=7 ttl=52 time=5.63 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=8 ttl=52 time=11.2 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=9 ttl=52 time=4.30 ms64 bytes from 220.181.57.217 (220.181.57.217): icmp_seq=10 ttl=52 time=4.17 ms
--- baidu.com ping statistics ---10 packets transmitted, 10 received, 0% packet loss, time 9013ms
rtt min/avg/max/mdev = 3.300/8.328/26.972/6.954 ms
real 0m10.006s
user 0m0.003s
sys 0m0.006s
不知道能不能满足你的需求
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询