search

Home  >  Q&A  >  body text

Python OS模块 用Python调用cmd命令是如何让他在后台静默执行(不会突然跳出cmd弹窗)

麻烦问下各位大神

如何让Python在执行os.system(cmd)是不弹窗执行,让他在后台静默执行,有没有这样的方法。谢谢

示例代码:

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import os

cmd = 'ping 127.0.0.1'

os.system(cmd)
黄舟黄舟2803 days ago948

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:47:33

    Use the run function of subprocess

    from subprocess import run
    run("ping 127.0.0.1",shell=True)

    reply
    0
  • Cancelreply