How to mount a network directory using python?

前端 未结 4 1877
闹比i
闹比i 2021-02-08 19:47

I need to mount a directory \"dir\" on a network machine \"data\" using python on a linux machine

I know that I can send the command via command line:

mk         


        
4条回答
  •  無奈伤痛
    2021-02-08 20:23

    I'd recommend you use 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' ) ] )
    

提交回复
热议问题