【问题标题】:Handle is Invalid: Calling BCP from Python using the subprocess module句柄无效:使用子进程模块从 Python 调用 BCP
【发布时间】:2014-05-20 12:55:27
【问题描述】:

我有一个项目,我将大量数据以文本文件的形式上传到 SQLServer。有一个 python 脚本使用函数SQLUpload 迭代调用 BCP 命令。这个函数的输入是:

SQLUpload(prefix,suffix,uploadingDirectory,formatFileDirectory,server,tableName,
                                                     userName,passWord)

使用子流程模块迭代调用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

此错误是否意味着我没有使用当前用户名和密码的权限?还是有别的意思?

提前致谢。

【问题讨论】:

标签: python sql-server command-line subprocess bcp


【解决方案1】:

由于某种原因重新启动工作。

我再次运行脚本。它从它离开的地方拿起然后工作。

奇怪。这是一些information on Windows Handles

【讨论】:

    猜你喜欢
    • 2018-05-12
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    相关资源
    最近更新 更多