这不会在sqlcmd中执行,如何从python3.2执行

时间:2013-04-03 01:38:22

标签: cmd sqlcmd python-3.3

我试图在call()Popen()

的python中执行此操作
sqlcmd -E -S .\ 
USE MASTER 
GO 
SELECT 
name AS [Logical_name], 
physical_name AS [File_Path], 
type_desc AS [File_Type], 
state_desc AS [State] 
FROM sys.master_files 
WHERE database_id = DB_ID(N'AdventureWorksLT2008_old')
GO

它会引发一些错误。现在,我想看看问题是什么。我制作了命令的.bat文件。我执行了它,只有sqlcmd -E -S .\被执行。其余部分则没有。如何在python中的cmd之后控制sqlcmd以执行其余的代码? 你能帮忙吗? 感谢

1 个答案:

答案 0 :(得分:0)

您需要指定一个输入选项,例如-q并删除GO命令。请以read the documentation为例。尝试:

sqlcmd -E -S .\ -q "
SELECT 
name AS [Logical_name], 
physical_name AS [File_Path], 
type_desc AS [File_Type], 
state_desc AS [State] 
FROM sys.master_files 
WHERE database_id = DB_ID(N'AdventureWorksLT2008_old')"

如果需要,或者将它们全部放在一行中。