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

4
  • 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 Commented Apr 11, 2013 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? Commented Apr 11, 2013 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. Commented Apr 11, 2013 at 20:48
  • @David Makogon I will move it and expand upon my answer as well. Commented Apr 12, 2013 at 14:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks I'll try to apply what you wrote :)
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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.