【问题标题】:Python Mount CIFS share with space in linuxPython 挂载 CIFS 与 linux 中的空间共享
【发布时间】:2014-07-09 21:19:10
【问题描述】:

我正在尝试使用下面的 python 在我的 linux 机器中使用空间挂载到 CIFS 共享:

from subprocess import call
t = mount -t cifs -o username=kalair2 "//10.32.135.87/root/Singapore Lab/SYMM"      /mnt/share
print t
if os.path.exists("/mnt/share"):
    print "/mnt/share path already exists"
else:
    call("mkdir /mnt/share")
    call("chmod 777 /mnt/share")
    print "mnt/share has been created"
call(t)

但最终出现错误... Traceback(最近一次调用最后一次):文件 “mounttest.py”,第 12 行,在 调用(t)文件“/usr/lib64/python2.6/subprocess.py”,第 478 行,调用中 p = Popen(*popenargs, **kwargs) 文件“/usr/lib64/python2.6/subprocess.py”,第 642 行,在 init errread, errwrite) 文件“/usr/lib64/python2.6/subprocess.py”,第 1234 行,在 _execute_child 中 raise child_exception 操作系统错误:[Err no 2] 没有这样的文件或目录

如果我在带有空格的 shell 中执行这个挂载命令,它就可以工作。谁能帮我解决这个问题?

【问题讨论】:

    标签: python-2.7


    【解决方案1】:

    尝试逃离你的空间:

    "//10.32.135.87/root/Singapore\ Lab/SYMM"
    

    【讨论】:

      【解决方案2】:

      call 应该使用一组参数调用 - 而不是带有参数的命令的单个字符串,如此处所述:https://docs.python.org/2/library/subprocess.html

      您的命令应如下所示:

      call(["mkdir", "/mnt/share"])

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-15
        • 1970-01-01
        • 2018-08-21
        • 1970-01-01
        • 2016-04-28
        • 2021-11-09
        • 2012-10-21
        • 1970-01-01
        相关资源
        最近更新 更多