开发者

Python making cmd invisible when using the os.system

开发者 https://www.devze.com 2023-03-17 06:53 出处:网络
I found out that i could ping a system on python by typing os.system(\'ping ip\') but whe开发者_Go百科n i execute it, it shows cmd.

I found out that i could ping a system on python by typing

os.system('ping ip')

but whe开发者_Go百科n i execute it, it shows cmd.

My question is, how do i ping someone on python without showing the cmd?


If you need only a ping, then it would be better to use something like ping.py.

In other cases use subprocess as suggested by @Sentinel


Look at the

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

module.

It gives you enough options for controlling the output.

Or use standard bash redirection in order to send the output to /dev/null


See my answer to hiding console when run in os.startfile()

0

精彩评论

暂无评论...
验证码 换一张
取 消