Search code examples
sqlsql-server-2008xp-cmdshell

How to run a batch file in xp_cmdshell


When I try to run this:

exec master..xp_cmdshell 'C:\f\alert.bat'

I get the following error message:

'C:\f\alert.bat' is not recognized as an internal or external command,
operable program or batch file.

How can I run this batch file using xp_cmdshell?

EDIT: The command above is verbatim. I am not using any parameter that has spaces in it.


Solution

  • I have several servers running, and I was trying to run this command from a remote server instead of a local one. So I was getting this error because the batch file was obviously not present on the remote server.