0

I'll explain the task requested from me:

I have two containers in Azure, one called "data" and one called "script". In the "data" container there's a txt file with data, and in the "script" container there's a script file.

Now, I need programatically (with WorkerRole) to execute the script file, with the content of the data file as parameters (Example: a script file that accepts a string 's' and returns to the screen "Hello, 's'", when 's' in the string given, and in the data file there's a string), and save the result of the run into another file which needs to be saved in another container called "result".

How do I do all these? I've already uploaded the files and created the blobs programatically, but I can't seem to understand how to execute the file of how to save its result to another file? Can I please have some help?

Thanks in advance

David Makogon
  • 69,407
  • 21
  • 141
  • 189
DanielY
  • 1,141
  • 30
  • 58
  • 1
    Here are the steps in pseudo code: 1. Retrieve the script from the blob(using `DownloadToStream()`) 2. Compile the script(I will leave this to you as I have no idea what format your script is) 3. Load parameters from blob(same as step 1) 4. Execute script with those parameters. If your script's can be written as lambda expressions then this becomes a lot easier as you can turn them into `Action`'s – jzworkman Apr 11 '13 at 19:51
  • @jzworkman Thanks alot! I knew the steps more or less but you definety put some things in order. My questions are 1) what is the difference between downloadText and downloadToStream()? and 2) What are exactly the command in C# for file execution? – DanielY Apr 11 '13 at 20:07
  • 1
    @jzworkman Please move your *comment* to an *answer* so people can vote on it appropriately and, assuming **user1067083** finds this answer acceptable, can properly do so. – David Makogon Apr 11 '13 at 20:48
  • @David Makogon I will move it and expand upon my answer as well. – jzworkman Apr 12 '13 at 14:35

1 Answers1

1

Here are the steps in pseudo code:

  1. Retrieve the script from the blob(using DownloadToStream())
  2. Compile the script(I will leave this to you as I have no idea what format your script is)
  3. Load parameters from blob(same as step 1)
  4. Execute script with those parameters.

If your script's can be written as lambda expressions then this becomes a lot easier as you can turn them into Action's

Edit based on your questiions:

  1. DownloadText() is no longer included in Azure Storage 2.0, you only have access to DownloadToStream(). Even if you are using an older version(say 1.7) I would recommend using DownloadToStream() in the event you ever upgrade in the future. This will prevent having to refactor your code.
  2. In terms of executing your script, depending on what type of script it is(if it is c# code you can use this example: Is it possible to dynamically compile and execute C# code fragments?. If you need to execute a different type of script you would need to run it using Process.Start and you can look at this example: http://www.dotnetperls.com/process-start

I do not have much experience with point number 2 but those are the processes I have heard and seen used.

Community
  • 1
  • 1
jzworkman
  • 2,695
  • 14
  • 20
  • Thanks I'll try to apply what you wrote :) – DanielY Apr 13 '13 at 19:16
  • OK @jzworksman I have a question - given the stream where the script is, how do I use Process.Start with the stream (I only have options to put filename in the startinfo), and another question - how do I save the output of the execution to file? – DanielY Apr 13 '13 at 19:40
  • You could use process.Start if you have a file that can execute the script in the stream. Otherwise you will need to compile the script to whatever language your script is in and execute it that way. One idea would be to save it as a file on the vm and then you could call process.start on that file. – jzworkman Apr 15 '13 at 14:12