简体   繁体   English

Amarok 1.4脚本:了解谁在运行您

[英]Amarok 1.4 script: knowing who's running you

I've been using Amarok 1.4 for a long time, switching to Bogdan Butnaru's packages when KDE stopped supporting it, and I'm now giving Pana a try. 我已经使用Amarok 1.4很长时间了,当KDE停止支持它时,切换到Bogdan Butnaru的软件包,现在我可以尝试Pana。

I realised that a script I wrote in Python for Amarok 1.4 will not immediately run without changes under Pana. 我意识到,我在Python中为Amarok 1.4编写的脚本如果没有在Pana下进行更改就不会立即运行。 But instead of converting my script , which basically comes down to replacing "amarok" with "pana" in the paths I use, I'd rather make it compatible with both the original Amarok 1.4 and Pana, so that I could be able to distribute only a single version of that script (and possibly modifying it later if other forks become popular). 但是,与其转换我的脚本 (基本上不归结为在我使用的路径中用“ pana”替换“ amarok”),而是让它与原始Amarok 1.4和Pana兼容,这样我就可以分发仅该脚本的单个版本(如果其他fork流行起来,可以稍后对其进行修改)。

So, is there a (Python(ic)) way for my script, running from within the player, to find out which program launched it? 那么,在播放器内部运行的脚本是否有一种(Python(ic))方式,可以找到启动该程序的程序?

import os

pid = os.getppid()
with open("/proc/%s/cmdline" % pid) as f:
    print f.readline()

Assuming you are running Linux. 假设您正在运行Linux。 Not sure if you need getppid() or getpid() here. 不知道这里是否需要getppid()或getpid()。 Not so pythonic maybe. 也许不是pythonic。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM