Executing bat file in stored procedure using SQL Server 2005

When I try to execute a bat file using xp_CMDShell, I get the message as an unrecognized command.

The following is the i command:

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

I received the message as follows:

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

Any suggestions. Let me know how to execute the bat file in a stored procedure. I am new to SQl Server.

Thanks Vinu

+4
source share
3 answers

Put the path in ""

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

xp_cmdshell may be a little picky about long file names, you use quotes and don't play the ball, double quotes may work sometimes, but if it still doesn't want to play the ball, try using the older 8.3 filename instead.

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

No parameter

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

With parameter

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

Perform and enjoy the decision :)

0
source

All Articles