我收到此错误:
回溯(最后一次调用):文件“app.py”,第 29 行,在 print(get_active_window_title()) 文件“app.py”,第 7 行,在 get_active_window_title output = subprocess.check_output('./app.sh' ) 文件“/home/rishabh/anaconda2/lib/python2.7/subprocess.py”,第 216 行,在 check_output 进程中 = Popen(stdout=PIPE, *popenargs, **kwargs) 文件“/home/rishabh/anaconda2/ lib/python2.7/subprocess.py”,第 394 行,在 init errread,errwrite)文件“/home/risabh/anaconda2/lib/python2.7/subprocess.py”,第 1047 行,在 _execute_child 中引发 child_exception OSError:[ Errno 13] 运行项目代码时权限被拒绝
当我尝试在全新的 ubuntu 安装上运行此代码时,该代码以前可以完美运行。chmod 不起作用。以下是代码
import sys
import os
import subprocess
import re
import cv2
def get_active_window_title():
output = subprocess.check_output('./app.sh')
if output.decode("utf-8") == "Desktop\n":
return "Desktop"
else:
root = subprocess.Popen(['xprop', '-root', '_NET_ACTIVE_WINDOW'], stdout=subprocess.PIPE)
stdout, stderr = root.communicate()
m = re.search(b'^_NET_ACTIVE_WINDOW.* ([\w]+)$', stdout)
if m != None:
window_id = m.group(1)
window = subprocess.Popen(['xprop', '-id', window_id, 'WM_CLASS'], stdout=subprocess.PIPE)
stdout, stderr = window.communicate()
else:
return None
match = re.match(b'WM_CLASS\(\w+\) = ".*", (?P<name>.+)$', stdout)
if match != None:
return match.group("name").strip(b'"')
return None
if __name__ == "__main__":
print(get_active_window_title())