简体   繁体   English

尝试从脚本执行二进制文件时,pkexec“找不到这样的文件或目录”

[英]pkexec "no such file or directory found" when trying to execute a binary from a script

I'm trying to execute a binary from a python script by using asyncio .我正在尝试使用asyncio从 python 脚本执行二进制文件。 I'm using the run command from here .我正在使用此处的运行命令。 I tried running it regularly, but I apparently don't have the permissions (even though it did work with another binary) so I do know that the file name is correct.我尝试定期运行它,但显然我没有权限(即使它确实可以与另一个二进制文件一起使用)所以我知道文件名是正确的。 I also saw that pkexec might need the full path so I gave it the full path just in case and I still got the same error: cannot run program./linkerd: No such file or directory我还看到 pkexec 可能需要完整路径,所以我给了它完整路径以防万一,但我仍然遇到同样的错误: cannot run program./linkerd: No such file or directory

import os
import asyncio

linkerd_f = linkerd_name() # The file's name in the directory
cwd = os.getcwd()
os.chmod(linkerd_f, 755)
asyncio.run(run(
    'pkexec .' + cwd + '/' + linkerd_f))

As for how I run the script, I simply run it through python: python3.7 script.py至于我是怎么运行脚本的,我简单的通过python运行: python3.7 script.py

Your error is being generated by pkexec itself as your call syntax is incorrect.由于您的调用语法不正确,您的错误是由 pkexec 本身生成的。

You used os.cwd() to get the CWD but then you prepend it with a .您使用os.cwd()来获取 CWD,但随后在其前面添加了. which invalidates the full path.这会使完整路径无效。

Effectively the equivalent of this:实际上相当于:

amos:/tmp$ ll simple.sh
-rwxr-xr-x 1 amos amos 73 Mar 16 11:51 simple.sh*
amos:/tmp$ pkexec .$PWD/simple.sh
Cannot run program ./tmp/simple.sh: No such file or directory

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

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