Search code examples
batch-fileparameter-passingsyntax-errorexecution

Calling a Batch file using parameters with spaces in the path in SQL Server Agent job


I am running a batch file from the below location in a SQL Server Agent Job step:

"D:\Program Files\Cincom\Control\2212\Prd\Dcls\DEV1-MIKE1_RUN_Batch_JOB"

I want to pass a parameter in to run an IF statement. However, when I do this:

"D:\Program Files\MyProgram\Dcls\DEV1-MIKE1_RUN_Batch_JOB 1"

I get the 'is not recognized as an internal or external command, operable program or batch file' error

Same thing with:

"D:\Program Files\MyProgram\Dcls\DEV1-MIKE1_RUN_Batch_JOB '1'"

And:

"D:\Program Files\MyProgram\Dcls\DEV1-MIKE1_RUN_Batch_JOB "1" "

I need to pass the parameter and I need to run the batch file from the given location. Any ideas?


Solution

  • Surround the batch file full path with quotes, then specify the parameters for your batch file:

    "D:\Program Files\MyProgram\Dcls\DEV1-MIKE1_RUN_Batch_JOB" 1