Python Sqlcmd:错误:打开或操作文件C时出错:

Python Sqlcmd:错误:打开或操作文件C时出错:,python,sql,sql-server,Python,Sql,Sql Server,我有一个python脚本,它使用子流程运行一些sql脚本 branch_path = "C:/devel/branch" #path used in command command_process = subprocess.Popen( ['sqlcmd', '-E', '-V1', '-S', 'MYPC', '-i', branch_path +"/DatabaseScripts/restore_db_mss.sql"], stdin=subprocess.PIPE, stdout=subp

我有一个python脚本,它使用子流程运行一些sql脚本

branch_path = "C:/devel/branch" #path used in command
command_process = subprocess.Popen(
['sqlcmd', '-E', '-V1', '-S', 'MYPC', '-i', branch_path +"/DatabaseScripts/restore_db_mss.sql"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True
)
command_output = command_process.communicate()[0]
print command_output
我得到这个错误:

Sqlcmd: Error: Error occurred while opening or operating on file C: (Reason: Access is denied).

我试着给我的机器正确的权限,但没有任何效果。我试着按照其他人的建议切换到管理员服务,但也不起作用。如果有任何帮助,我们将不胜感激。

您需要用引号将路径括起来。@pmbAustin我尝试使用括号中括起来的整个路径,而不是连接分支路径,但仍会抛出相同的错误。您可以尝试将路径作为原始字符串读取吗<另一方面,代码>['sqlcmd'、'-E'、'-V1'、'-S'、'MYPC'、'-i',r“C:/devel/branch/DatabaseScripts/restore_db_mss.sql”]。Start cmd[右键单击]“作为管理员”还检查sql server服务是否具有“C:\”权限。在没有python的情况下,它在cmd中工作吗?您是否尝试过:?@user2853437不工作