【问题标题】:Executing a bat file inside a Stored Procedure using SQL server 2005使用 SQL Server 2005 在存储过程中执行 bat 文件
【发布时间】:2011-08-11 09:28:58
【问题描述】:

当我尝试使用 xp_CMDShell 执行 bat 文件时,我收到一条消息为无法识别的命令。

以下是我执行的命令:

EXEC master..xp_CMDShell 'C:\Documents and Settings\adcxqcv\Desktop\PQA\sample.bat' 

我收到一条消息如下:

'C:\Documents' is not recognized as an internal or external command,
operable program or batch file.
NULL

任何建议。让我知道如何在存储过程中执行 bat 文件。 我是 SQL Server 的新手。

谢谢, 维努

【问题讨论】:

    标签: sql-server


    【解决方案1】:

    把路径放在“”里面

    EXEC master..xp_CMDShell '"C:\Documents and Settings\adcxqcv\Desktop\PQA\sample.bat"' 
    

    【讨论】:

      【解决方案2】:

      xp_cmdshell 对长文件名可能有点挑剔,你使用引号但它不玩球,双引号有时可以工作,但如果它仍然不想玩球,那么尝试使用旧的 8.3 文件名而是。

      exec master..xp_cmdshell 'c:\docume~1\adcxqcv\Desktop\PQA\sample.bat' 
      

      【讨论】:

        【解决方案3】:

        无参数

        exec(' xp_cmdshell ''C:\script\test.bat'); --your bat file location(path)
        

        带参数

        exec(' xp_cmdshell ''C:\script\test.bat '+@ecistate+' '+@stateid+' '+@pcno+''''); --your bat file location(path)
        

        执行并享受解决方案:)

        【讨论】:

          猜你喜欢
          • 2016-11-02
          • 2010-12-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多