WebJob run cmd cannot find continuous webjob executable

Conor McCarthy 30 Reputation points
2023-06-28T12:24:08.8333333+00:00

I have deployed one continuous webjob (a .Net Core console app) and 6 triggered webjobs.

Each triggered webjob just contains a run.cmd which contains the full path to the continuous webjob, along with a command line parameter which will tell the executable to perform a one-off task.

e.g.

C:\home\site\wwwroot\App_Data\jobs\continuous\directoryname\mywebjob.exe specifictaskname

All of the wejobs are being deployed using an Azure Devops pipeline. The artifact containing the .net console app has a separate directory structure with the triggered webjob cmd files, and I use a copy command in the release pipeline to deploy them.

Now here is the weird part:

After deploying the app, when I try to manually trigger one of the triggered webjobs from the Azure portal, it fails with:

xxxx is not recognized as an internal or external command, operable program or batch file.

The entry in the log shows the exact command line to the correct location of the executable, where it exists.

NOW if I go and edit the cmd file directly using console tools (no real edit, just add a space, delete it and save) - now when I go to trigger the webjob, it works.

What is going on here?

Full log file:

[06/28/2023 12:09:30 > 184605: SYS INFO] Status changed to Initializing

[06/28/2023 12:09:30 > 184605: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'

[06/28/2023 12:09:30 > 184605: SYS INFO] Status changed to Running

[06/28/2023 12:09:30 > 184605: ERR ] 'C:\home\site\wwwroot\App_Data\jobs\continuous\mywebjob\mywebjob.exe' is not recognized as an internal or external command,

[06/28/2023 12:09:30 > 184605: INFO]

[06/28/2023 12:09:30 > 184605: ERR ] operable program or batch file.

[06/28/2023 12:09:30 > 184605: INFO] C:\local\Temp\jobs\triggered\OBM.DailyProcessing.WebJob\dm2y3je2.dd3>C:\home\site\wwwroot\App_Data\jobs\continuous\mywebjob\mywebjob.exe mytask

[06/28/2023 12:09:30 > 184605: SYS INFO] Status changed to Failed

[06/28/2023 12:09:30 > 184605: SYS ERR ] Job failed due to exit code 1

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 14,280 Reputation points MVP Volunteer Moderator
    2023-06-28T14:08:35.1233333+00:00

    Based on the issue you've described, it sounds like there might be an encoding issue with your run.cmd file. This can sometimes happen if the file is encoded in a format that Azure doesn't recognize, such as UTF-8 with BOM.

    Here's a potential solution:

    1. Add a run.cmd file to your WebJob in Visual Studio (same place as your Program.cs)
    2. Make sure to set this file's 'Copy to Output Directory' to Copy if newer (in the file properties)
    3. In that file, just add one line that has: mywebjob.exe /dosomething Replace mywebjob.exe /dosomething with your own executable and parameters.

    When deployed to Azure, this file will take precedence over the .exe, and will end up running the .exe with your parameters​.

    If this doesn't solve your issue, I'd recommend checking the encoding of your run.cmd files to ensure they're compatible with Azure. If you're using an editor like Visual Studio Code, you can check the encoding in the bottom-right corner of the window and change it if necessary. Try switching to UTF-8 without BOM if that's not the current encoding.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.