【问题标题】:python how to finding process location/pathpython如何找到进程位置/路径
【发布时间】:2021-04-08 13:38:59
【问题描述】:

我想制作一个脚本来自动化一些程序,其中一个功能是打开和关闭它们。 现在我使用文件夹中的完整路径打开应用程序:

C:\\Users\\xxxx\\xxxxx\\xxxxx\googlechrome.exe

我不喜欢这种方式,因为它只能在我的电脑上工作 我有什么办法让程序可以在没有完整路径的情况下找到它吗? 寻找流程或其他东西? 我希望它是动态的,如果我在不同的 PC 上运行相同的脚本,他可以自己找到路径。

【问题讨论】:

标签: python-3.x automation


【解决方案1】:

PyPi 中的 psutil 是一个可以帮助您的库。

示例:


In [7]: p = psutil.Process(17032)

In [8]: p
Out[8]: psutil.Process(pid=17032, name='pythonw.exe', status='running', started='18:29:30')

In [9]: p.exe()
Out[9]: 'C:\\Users\\[user_name]\\AppData\\Local\\Programs\\Python\\Python38-32\\pythonw.exe'

【讨论】:

    猜你喜欢
    • 2021-03-17
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-17
    相关资源
    最近更新 更多