I'm trying to setup a sqlserver agent job of type CmdExec for running an executable inside %programdata%\my company folder. But if I use %programdata%\my company\myexec.exe, the job fails to start because it says it can't find the file. With the absolute path C:\ProgramData\my company\myexec.exe it works. Anybody knows a way to run the job successfully using the special folder alias?
migrated from stackoverflow.com Jan 20 '12 at 21:17
|
It will depend on what account you are using for SQL Server Agent service. If the %ProgramData% is a system variable it should be seen by any account on the server where the instance is running. Where, user variables are local to the user profile it was configured under. Edit |
|||
|
|
|
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. |
|||||||||||
|
|
You can force environment variable expansion by calling cmd.exe /c "mycommand", though you do have to be very careful with your quoting and double quoting. For example, assuming the OP's original job step was (literally, including the quotes)
you can replace this with:
...and it will work. @Shawn points out that this will only work for system environment variables, or those set for the SQL agent user, but %programdata% should be fine. |
|||
|
|