可能的解决方案可能是:
开始交互式会话。
sudo -s <<< "cd dir ; command"
Run Code Online (Sandbox Code Playgroud)
或者
sudo /bin/bash -c "cd dir ; command"
Run Code Online (Sandbox Code Playgroud)
但我没有 /bin/bash /bin/sh /bin/su 或其他 sudoer 权限
在 sudo 完成之前更改目录。
cd dir ; sudo command
Run Code Online (Sandbox Code Playgroud)
但我无权进入目录。
我需要一个一般情况下的密码集(如 Popen cwd),所以下面不是我可以使用的答案:
sudo command /path/to/file
Run Code Online (Sandbox Code Playgroud)我正在尝试编写的是带有 sudo=True/False 选项的 python Popen 包装器,目前我正试图以某种方式让 cwd 参数起作用。