python - 使用 python 查找 nfs 服务器的名称
问题描述
我希望找到一种方法来查找来自 python 中的特定文件/目录的 nfs 服务器的名称,而不是使用外部命令。
这是我到目前为止所拥有的,看起来太脆弱了。首先,shell命令本身:
$ findmnt -Do SOURCE /scratch
SOURCE
scratch_server.example.com:/scratch
蟒蛇内部:
import subprocess, sys
cmd = ['findmnt', '-Do', 'SOURCE', '/scratch']
proc = subprocess.run(cmd, capture_output=True)
server = proc.stdout.decode(sys.stdout.encoding).split('\n')[1].split(':')[0]
print(server)
scratch_server.example.com
有没有更好、更“pythonic”的方式来做到这一点?我无法想象这是最佳实践。需要明确的是,我根本不关心执行子进程、超时等的最佳方式。我真的完全不必在子流程中执行此操作。谢谢。
解决方案
推荐阅读
- python - 尝试引用变量时出现 NameError 问题
- c - Linux system() 调用返回 -1 但命令执行成功
- php - ajax 没有得到价值?
- azure-active-directory - 如何授权 Azure B2C 用户读取 Blob 存储
- python - 如何获得 github-action Tkinter 版本 >= 8.6 [MACOS]?
- html - 如何增加 react-draft-wysig 中的默认行数?
- java - 没有得到正确的输入来检查重复
- javascript - 反应本机导航标题溢出
- node.js - Win10 上的 ioBroker
- python - 使用 np.arange() 在列表理解期间附加字符串