Using Startup Task with command line redirection in Windows Azure Role

Recently while working on an incident I found that if you use Windows Azure Startup task with launch some application along with command line redirection (to collect log) directly as below, it may not launch the startup task:


   1: <Task commandLine="Startup\Application.exe >>  C:\temp\logfilename.log 2>&1" executionContext="elevated" taskType="background" relativePath="approot\bin" />


As startup task will not be launched, there will not be any command line redirection log collected. After little more work I found that most of the std* redirection are done directly from BATCH/CMD script in the Startup task and works fine. Redirection directly from startup commandline is not suggested and to solve this problem what you can do is create a launcher.bat and place the command + redirection code to get it working.


Step 1: First create a batch file which includes the command line as required (Launcher.bat)

   1:  @ECHO ON
   2:  @ECHO "Launcher"
   3:  md C:\temp
   4:  Startup\Application.exe  >> C:\temp\logfilename.log 2>&1


Step 2: After it modify the ServiceDefinition to use launcher.bat as commandline as below:

   1: <Task commandLine="Startup/launcher.bat" executionContext="elevated" taskType="background" relativePath="approot\bin" />


After I modified the startup code as above and did test in a web role with Windows Azure VM everything worked fine.

Comments (1)

  1. Vel says:

    Hello Avkash,

    Thanks for this blog…. I am looking for an answer as to why my startup command is not firing. I have a cmd file in my Startup commandline where the files are in bin directory. any tips would be great. I will try to do it your way and see if it works…