[英]Using subprocess and pkexec
I'm trying to use run a command alongside with pkexec, but is says no such file is found. 我正在尝试将运行命令与pkexec一起使用,但是据说没有找到这样的文件。
process = subprocess.Popen(["pkexec cat", "/dev/input/event4"], stdout=subprocess.PIPE)
for line in iter(process.stdout.readline, ''):
sys.stdout.write(line)
OSError: [Errno 2] No such file or directory
OSError:[Errno 2]没有这样的文件或目录
However, path is okay and the file is there. 但是,路径尚可,并且文件在那里。
You probably want to use: 您可能要使用:
subprocess.Popen(["pkexec", "cat", "/dev/input/event4"])
Since subprocess.Popen
quotes each entry in the list; 由于
subprocess.Popen
引用了列表中的每个条目; so your example is the same using this on the commandline: 因此您的示例在命令行中使用以下示例是相同的:
$ "pkexec cat" /dev/input/event4
Instead of: 代替:
$ pkexec cat /dev/input/event4
From the documentation (emphasis mine): 从文档 (重点是我的):
args is required for all calls and should be a string, or a sequence of program arguments.
args是所有调用所必需的,并且应为字符串或程序参数序列。 Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (eg to permit spaces in file names) .
通常优选提供参数序列,因为它允许模块处理任何必需的参数转义和引用(例如,在文件名中允许空格) 。 If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.
如果传递单个字符串,则外壳程序必须为True(请参见下文),否则该字符串必须简单地命名要执行的程序而无需指定任何参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.