2

I have a startup task for my webrole that download some executable file from a blob and then proceed to the installation.

From a .cmd file, I start a power shell script that download the files, then I start the file from the .cmd.

The script works fine if I run it manually through RDP after the publishing is done.

But, when running as startup script, it sometimes (often) fail at different points.

The taskType is set to background.

Last time, the error was that the command PowerShell does not exists...

Also, I use powershell -command set-executionpolicy unrestricted before running my PS script, but I read here that other task may reset this setting and make mine fail.

Quite a mess.

So that makes me think that if I could wait for all other task to perform before starting mine, it would eliminate these kinds of problems

I suppose I could check if some process is running and wait for it to finish, but I have no clue wich process to check.

Or maybe there's another solution.

~edit~

I read here that the error about powershell not existing may be caused by the batch file being saved as UTF-8 in visual studio. I re-writed it from scratch in notepad++ and made sure it is save as ANSI. Then, same error. The full message is :

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

Again, the script run perfectly from command line in remote desktop.

Johnny5
  • 6,664
  • 3
  • 45
  • 78
  • Can you try changing your `taskType` from **simple** to **background**? RDP is enabled via **background** which may cause you this issue. – SliverNinja - MSFT Aug 03 '12 at 19:52
  • The `taskType` is already set to `background`, I forgot to mention it. – Johnny5 Aug 03 '12 at 20:11
  • What are you installing? Does it add any functionality to IIS? There is a process called IISConfigurator.exe which bootstraps IIS but I din't have enough context in your question around what you're attempting to achieve with said installers – cory-fowler Aug 04 '12 at 17:55
  • I am installing the matlab compiler runtime. I didnt write it in the question because it is not a _matlab_ issue. The part of my script that is usually failling is the download of the installer. – Johnny5 Aug 05 '12 at 03:18

2 Answers2

0

It would be possible to set an environment variable at the end of the script that is required to finish, then in the script which is awaiting the dependencies, loop until the environment variable is set, then kick off its activities.

You could also run everything from a single powershell script and use the '-asjob' switch on your installer statement, use the 'wait-job' cmdlet to block until the task is complete then carry on. Powershell also offers a '?!' operator which ensures the last statement executed properly.

cory-fowler
  • 4,020
  • 2
  • 18
  • 29
  • The problem is that I don't have control over the other tasks. For exemple, the setup of the remote desktop. It is MS code. – Johnny5 Aug 05 '12 at 03:19
0

This might be caused by an encoding issue. As mentioned in this answer you should save your file in ASCII to ensure correct interpretation of your script.

From the linked answer:

Open your whatever.cmd file with your VS 2012 Ultimate. Click on File->Save whatever.cmd as -> on the dialog there is little arrow next to the [save] button. It will show up a menu that will have the option Save with Encoding.

Select it. Now choose "US-ASCII Codepage 20127" from the list of available encodings.

Community
  • 1
  • 1
Lasse Christiansen
  • 10,205
  • 7
  • 50
  • 79