1

I have a simple file in the root of my Web project (which is tied to a Web worker role). The file is named Startup.cmd. This file contains the following line: dir > directory.txt. It executes properly when I run it from the command line and outputs a list of the directory contents to file named directory.txt as you would expect. Similarly, the line ECHO Write this line to file > output.txt does not appear to work either.

Inside ServiceDefinition.csdef for my Azure Cloud Service project, I have the following lines:

<WebRole name="Website" vmsize="Small">
    <Startup>
        <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple"></Task>
    </Startup>
    ....
</WebRole>

I believe it is finding the file, because I have tried changing the path and it will throw a build error that it cannot find it. The issue is that when I check my /bin/ directory after debugging to the Azure Debugging Environment, I see Startup.cmd (I have it set to Copy always) but I do not see directory.txt. I'm not sure of another way to confirm that it executed properly.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
Kyle B.
  • 5,737
  • 6
  • 39
  • 57
  • worth reading: http://blog.smarx.com/posts/windows-azure-startup-tasks-tips-tricks-and-gotchas and http://blogs.msdn.com/b/cclayton/archive/2012/05/17/windows-azure-start-up-tasks-part-1.aspx – Rory Jun 28 '15 at 18:24

1 Answers1

0

I found the following MSDN article useful: http://msdn.microsoft.com/en-us/library/hh180155.aspx.

As a result, I made some changes to my Startup.cmd file. I changed the command to:

ECHO The current version is %MyVersionNumber% >> "%TEMP%\StartupLog.txt" 2>&1
EXIT /B 0

However, this did not appear to put the output in my temporary directory for my system: C:\Users\username\AppData\Local\Temp. I'm going to presume this is because the Azure Compute Emulator uses a different temp directory I am unaware of.

I changed my Startup.cmd to:

ECHO The current version is %MyVersionNumber% >> "c:\temp\StartupLog.txt" 2>&1
EXIT /B 0

And updated my configuration to:

<WebRole name="Website" vmsize="Small">
  <Startup>
      <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple">
          <Environment>
              <Variable name="MyVersionNumber" value="1.0.0.0" />
              <Variable name="ComputeEmulatorRunning">
                  <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
              </Variable>
          </Environment>
      </Task>
  </Startup>
  ...
</WebRole>

And this did appear to write the file to C:\temp\ upon starting the debugger.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
Kyle B.
  • 5,737
  • 6
  • 39
  • 57
  • sample folder structure for the initial cmd C:\Resources\temp\24eb9559640c4fc0be2798ff81064a3c.myclient\RoleTemp\StartupLog.txt – Aravind Nov 20 '15 at 11:40