如何从python脚本卸载

时间:2016-10-28 08:30:59

标签: python subprocess gksudo umount

我想卸载名为VirtualDVD的安装点。 我想运行命令“gksudo umount VirtualDVD”

我的功能是:

def umount(self):
    '''unmounts VirtualDVD'''
    cmd = 'gksudo umount VirtualDVD'
    proc = subprocess.Popen(str(cmd), shell=True, stdout=subprocess.PIPE).stdout.read()
    print proc

我从终端尝试“gksudo umount VirtualDVD”,一切正常。

我从子进程尝试“gksudo umount VirtualDVD”,它失败了...... 它弹出gksudo对话框,我可以输入我的密码,但似乎umount失败,因为VirtualDVD仍然挂载。 为什么呢?

1 个答案:

答案 0 :(得分:0)

我想通了......我应该用安装点的完整路径卸下。 我按照以下方式更改了umount功能,它可以工作......

def umount(self):
    '''unmounts VirtualDVD'''
    #get virtualdvd folder
    home = QtCore.QDir.homePath()
    vpath = home + "/VirtualDVD"

    cmd = 'gksudo umount ' + vpath
    proc = subprocess.Popen(str(cmd), shell=True, stdout=subprocess.PIPE).stdout.read()
    print proc
相关问题