处理无效:使用子进程模块从Python调用BCP
我有一个项目,需要把很多文本文件的数据上传到SQLServer。为了实现这个,我写了一个Python脚本,这个脚本通过一个叫SQLUpload
的函数反复调用BCP命令。这个函数的输入是:
SQLUpload(prefix,suffix,uploadingDirectory,formatFileDirectory,server,tableName,
userName,passWord)
然后,使用subprocess模块来反复调用BCP命令的那一行代码如下(如果你需要更多代码,请留言):
batchCommand = 'BCP ' + tableName + ' in ' + os.path.join(directory,dataFile) + ' -U ' \
+ userName + ' -P ' + passWord + ' -S ' + server \
+ ' -f ' + formatFileDirectory
err = subprocess.call(batchCommand,stderr=subprocess.PIPE,shell=True)
出现的错误如下:
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
SQLUpload(prefix,suffix,uploadingDirectory,formatFileDirectory,server,tableName,userName,passWord)
File "H:\Engineering\MWDownload\HDC\Scriptfile\SQLUploader - Local.py", line 66, in SQLUpload
err = subprocess.call(batchCommand,stderr=subprocess.PIPE,shell=True)
File "C:\Python33\lib\subprocess.py", line 523, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Python33\lib\subprocess.py", line 789, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "C:\Python33\lib\subprocess.py", line 1006, in _get_handles
c2pwrite = self._make_inheritable(c2pwrite)
File "C:\Python33\lib\subprocess.py", line 1038, in _make_inheritable
_winapi.DUPLICATE_SAME_ACCESS)
OSError: [WinError 6] The handle is invalid
这个错误是说我当前的用户名和密码没有权限吗?还是说其他什么问题?
提前谢谢你们。