HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

sqlagent job - using system folder path with CmdExec

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
pathcmdexecsqlagentwithsystemfolderusingjob

Problem

I'm trying to setup a SQL Server agent job of type CmdExec for running an executable inside %programdata%\my company folder.

If I use %programdata%\my company\myexec.exe, the job fails because it apparently can't find the file.

But it works with the absolute path:

C:\ProgramData\my company\myexec.exe


How can I run the job successfully using the special folder alias?

Solution

SQL Agent doesn't shell out the command like that. You'll need to write a batch file with the system variable in it, then call the batch file from the SQL Agent job. The system variables don't get resolved if they are actually in the agent job step.

Context

StackExchange Database Administrators Q#11079, answer score: 5

Revisions (0)

No revisions yet.