简体   繁体   English

Python 使 cmd 在使用 os.system 时不可见

[英]Python making cmd invisible when using the os.system

I found out that i could ping a system on python by typing我发现我可以通过键入来 ping python 上的系统

os.system('ping ip')

but when i execute it, it shows cmd.但是当我执行它时,它显示 cmd。
My question is, how do i ping someone on python without showing the cmd?我的问题是,我如何在 python 上 ping 某人而不显示 cmd?

Look at the看着那(这

http://docs.python.org/library/subprocess.html http://docs.python.org/library/subprocess.html

module.模块。

It gives you enough options for controlling the output.它为您提供了足够的选项来控制 output。

Or use standard bash redirection in order to send the output to /dev/null或使用标准 bash 重定向,以便将 output 发送到 /dev/null

If you need only a ping, then it would be better to use something like ping.py .如果您只需要一个 ping,那么最好使用类似ping.py的东西。

In other cases use subprocess as suggested by @Sentinel在其他情况下,使用subprocess建议的子流程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM