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?

  • 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

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

  • 1
    If working directory is needed for script, you may need something like: cmd.exe /c "cd /d c:\temp && c:\temp\test.bat" – sonyisda1 Feb 8 at 0:36

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


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.


only "c:\test.bat" will do the job

  • 1
    Hi, Welcome to the site. While your answer may be useful it's usually better to include some more details as to why this would work while the command in the question doesn't. – Tom V Aug 22 '19 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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