我需要在 linux 机器上使用 python 在网络机器“data”上挂载目录“dir”
我知道我可以通过命令行发送命令:
mkdir ~/mnt/data_dir
mount -t data:/dir/ ~/mnt/data_dir
但是我如何从 python 脚本发送这些命令?
最佳答案
我建议您使用 subprocess.checkcall
。
from subprocess import *
#most simply
check_call( 'mkdir ~/mnt/data_dir', shell=True )
check_call( 'mount -t whatever data:/dir/ ~/mnt/data_dir', shell=True )
#more securely
from os.path import expanduser
check_call( [ 'mkdir', expanduser( '~/mnt/data_dir' ) ] )
check_call( [ 'mount', '-t', 'whatever', 'data:/dir/', expanduser( '~/mnt/data_dir' ) ] )
关于python - 如何使用python挂载网络目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2232420/