V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
squallcx
V2EX  ›  Python

请教如何用 psutil 模块获取用 subprocess.Popen 的程序 command line?

  •  
  •   squallcx · Feb 13, 2015 · 3228 views
    This topic created in 4100 days ago, the information mentioned may be changed or developed.
    import psutil
    import subprocess

    DETACHED_PROCESS = 0x00000008
    p=subprocess.Popen(["Go.exe","ID"],creationflags=DETACHED_PROCESS)

    for x in psutil.get_process_list():
    try:
    if x.name()=="Go.exe":
    print x.name(),x.pid,x.cmdline()
    except:
    continue

    执行代码打印
    Go.exe 27612 []

    只能获取到空白的command line,我想用command辨別,kill特定ID的程序,有没有比较靠谱的方法?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2460 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 00:01 · PVG 08:01 · LAX 17:01 · JFK 20:01
    ♥ Do have faith in what you're doing.