Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
SQL
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
Posted
Updated 27-Mar-21 3:39am

1 solution

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:
SQL
SET @Variable = '"C:\Microsoft Dynamics\SL\Applications\LogFacturacion\LOGERROR002211.txt"'
SET @CMDSQL = 'C:\Execute.bat ' + @Variable
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900