如何在sql server上执行bat文件 [英] how can I execute a bat file on sql server
本文介绍了如何在sql server上执行bat文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello社区
我正在尝试通过SQL存储过程打开文件文本的过程
我创建了一个文件C:\Execute.bat。 bat文件包含下一个命令
START C:\ Windows \ NOTEPAD.EXE%1其中%1是将成为文本文件所在路径的入口参数需要打开。
这是我的SQL代码:
Hello Community
I'm Trying a process to open a file text through a SQL store procedure
I made a file on C:\Execute.bat. The bat file contain the next command
START C:\Windows\NOTEPAD.EXE %1 where "%1" is the entry parameter that will be the path where is located the text file where i need to open.
This is my SQL code:
DECLARE @Variable VARCHAR(100)
DECLARE @CMDSQL VARCHAR(1000)
SET @Variable = 'C:\Microsoft Dynamics\SL\Applications\LogFacturacion\LOGERROR002211.txt'
SET @CMDSQL = 'C:\Execute.bat' + @Variable
EXEC xp_CMDShell @CMDSQL
执行此过程时,我收到此消息结果
输出:
文件名,目录名或卷标语法不正确
When I execute the process I obtain this message result
Output:
Filename, directory name or volume label syntax are incorrect
推荐答案
你无法运行记事本或具有GUI的任何其他程序,因为通过xp_cmdshell启动的进程作为后台进程运行,因此无法显示GUI。请参见此处 [ ^ ]。执行命令只会挂起。
如果你想运行其他非GUI程序,你必须在<$ c之后加一个空格$ c>'C:\ Execute.bat'并引用双引号中的文件路径,因为它包含空格:
You can not run Notepad or any other program with a GUI because processes started via xp_cmdshell run as a background process and are therefore not able to show a GUI. See here[^]. The execution of the command will just "hang".
If you want to run some other non-GUI program, you would have to include a space after'C:\Execute.bat'
and quote the file path in double-quotes because it contains a space:
SET @Variable = '"C:\Microsoft Dynamics\SL\Applications\LogFacturacion\LOGERROR002211.txt"'
SET @CMDSQL = 'C:\Execute.bat ' + @Variable
这篇关于如何在sql server上执行bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文