Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm attempting to run a (Windows) batch file from within a SQL Server agent job under SQL Server 2008 R2. In the Job Steps, I've created a new step, set its type to "Operating system (CmdExec)". I initially tried to put just the batch file name in the "Command" field. It gives an error that it can't find the file.

Then I tried: cmd.exe c:\test.bat

This starts, but never completes (and it doesn't look like it's actually working anyway).

I tried wrapping the batch file name in quotes: cmd.exe "C:\test.bat" but that also doesn't make any difference.

What is the magical combination to get this to work?

share|improve this question
Were you using the complete path when you got the "file not found" error? Is the path valid on the executing server, not just your workstation? Are the paths within the batch file absolute? – Jon of All Trades Dec 13 '11 at 22:12
Yes, I'm using the full path. It is the correct path on the server running it. The batch file is nothing more than a simple test: echo > C:\temp\itworks.txt – Paul Mrozowski Dec 14 '11 at 12:45
up vote 8 down vote accepted

If memory serves me correctly:

cmd.exe /c "c:\test.bat"

Quotes are needed if there are any spaces in the path or file name

share|improve this answer
Yep, that seems to work. – Paul Mrozowski Dec 14 '11 at 12:53

As well check the permissions used for the Job Agent Service. Could be that the user running the service does not have permission to see the file.

Good Luck

share|improve this answer

Check that you have permissions to run the batch file on that drive and folder location.

Don't forget when you run it manually your credentials are used but when it runs automatically by SQL Agent, the agent's credentials and permissions are used.

share|improve this answer
Why the downvote? – ivanmp Feb 18 '15 at 19:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.