【问题标题】:Python+CMD+tasklist (windows)Python+CMD+任务列表(windows)
【发布时间】:2018-02-10 13:23:27
【问题描述】:
import os
os.system('tasklist')

如何从该命令中提取任何内容?它显示了所有任务,但是当我执行print(os.system('tasklist')) 时,它会打印出 0。 是否有可能使此代码有用?

【问题讨论】:

    标签: python windows python-3.x command-prompt taskmanager


    【解决方案1】:

    这是访问我认为您正在寻找的数据的另一种方法:

    import subprocess
    
    subprocess.getoutput('tasklist').split('\n')
    
    # ['',
    #  'Image Name                     PID Session Name        Session#    Mem Usage',
    #  '========================= ======== ================ =========== ============',
    #  'System Idle Process              0 Services                   0         24 K',
    #  'System                           4 Services                   0         44 K',
    #  'smss.exe                       284 Services                   0         80 K',
    #  'csrss.exe                      384 Services                   0      1,660 K',
    #  'wininit.exe                    448 Services                   0        156 K',
    #  'csrss.exe                      480 Console                    1     10,996 K',
    #  'services.exe                   516 Services                   0      5,440 K',
    #  'winlogon.exe                   540 Console                    1      2,196 K',
    #  ...
    # ]
    

    【讨论】:

      猜你喜欢
      • 2014-02-04
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-24
      • 1970-01-01
      相关资源
      最近更新 更多