我目前正在为客户编写脚本。
这个脚本从配置文件中读取信息。 其中一些信息被存储在变量中。
之后,我想使用subprocess.call来执行挂载命令, 因此我使用这些变量来构建挂载命令。
call("mount -t cifs //%s/%s %s -o username=%s" % (shareServer, cifsShare, mountPoint, shareUser))
然而,这并不起作用。
Traceback (most recent call last):
File "mount_execute.py", line 50, in <module>
main()
File "mount_execute.py", line 47, in main
call("mount -t cifs //%s/%s %s -o username=%s" % (shareServer, cifsShare, mountPoint, shareUser))
File "/usr/lib64/python2.6/subprocess.py", line 470, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
首先使用以下命令构建:
mountCommand = 'mount -t cifs //%s/%s %s -o username=%s' % (shareServer, cifsShare, mountPoint, shareUser)
call(mountCommand)
也会导致相同的错误。
call(['mount', '-t', 'cifs', '//%s/%s' % (shareServer, cifsShare), mountPoint, '-o', 'username=%s' % shareUser])
- Andrea Corbellini