我正在尝试使用如下所示的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行,in call(t)File" /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 OS错误:[错误2]没有这样的文件或目录
如果我在shell中用空格执行这个mount命令,它会起作用。任何人都可以帮我这个吗?
答案 0 :(得分:0)
尝试逃离你的空间:
"//10.32.135.87/root/Singapore\ Lab/SYMM"
答案 1 :(得分:0)
call
- 不是带参数的命令的单个字符串,如下所示:https://docs.python.org/2/library/subprocess.html
您的命令应如下所示:
call(["mkdir", "/mnt/share"])