Avkash Chauhan's Blog

Windows Azure, Windows 8, Cloud Computing, Big Data and Hadoop: All together at one place.. One problem, One solution at One time...

Using Startup Task with command line redirection in Windows Azure Role

Using Startup Task with command line redirection in Windows Azure Role

Rate This
  • Comments 1

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:

ServiceDefinition.csdef:

   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.

Leave a Comment
  • Please add 8 and 5 and type the answer here:
  • Post
  • 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...

    Regards

    Vel

Page 1 of 1 (1 items)