c# - Azure辅助角色中的程序执行可以在本地模拟器中运行,但不能在云中运行

标签 c# c++ azure azure-worker-roles fractals

我有一个以辅助角色运行的 exe 文件,并在辅助角色中包含以下代码:

 try
        {
            //Get local storage path
            var locRes = RoleEnvironment.GetLocalResource("data");
            var localStoragePath = String.Format(locRes.RootPath);

            var p = new Process();
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            p.StartInfo.FileName = this._processorExecutable;
            p.StartInfo.EnvironmentVariables["TEMP"] = localStoragePath;
            p.StartInfo.EnvironmentVariables.Add("transparency", "1");
            p.StartInfo.EnvironmentVariables.Add("verbose", "1");
            p.StartInfo.EnvironmentVariables.Add("in", _inFile);
            p.StartInfo.EnvironmentVariables.Add("format", filetype);
            p.StartInfo.EnvironmentVariables.Add("out", localStoragePath + msg.flameOutFile);
            msg.flameOutFile = localStoragePath + msg.flameOutFile;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.Start();
            _cloudUtil.StoreNewLogMessage(new LogMessage(p.StandardOutput.ReadToEnd()));
            _cloudUtil.StoreNewLogMessage(new LogMessage(p.StandardError.ReadToEnd()));
            p.WaitForExit();
            var fi = new FileInfo(msg.flameOutFile);
        }
        catch (Exception ex)
        {
            _cloudUtil.StoreNewLogMessage(new LogMessage("Error: " + ex));
        }

有问题的 exe 是一个用于渲染火焰分形的命令行程序,可以在此处找到: https://code.google.com/p/flam3/downloads/list

它在模拟器中按预期本地工作。我能够向程序提供一个 xml 文件,它将用于渲染火焰分形并输出图像文件。快乐的日子。

我的问题是,当我在云生产环境中运行它时,我从程序中收到一个我无法解释的错误。

我得到的错误是:

FLAM3:从临时文件读取字符串:参数无效

这源于分形程序中的以下代码:

    char *flam3_print_to_string(flam3_genome *cp) {

   FILE *tmpflame;
   long stringbytes;
   char *genome_string;

   int using_tmpdir = 0;
   char *tmp_path;
   char tmpnam[256];

   tmpflame = tmpfile();
   if (NULL==tmpflame) {
#ifdef _WIN32       
       // This might be a permissions problem, so let's try to open a
       // tempfile in the env var TEMP's area instead
       tmp_path = getenv("TEMP");

       if (tmp_path != NULL) {
          strcpy(tmpnam, tmp_path);
          strcat(tmpnam, "\\fr0st.tmp");
          tmpflame = fopen(tmpnam, "w+");
          if (tmpflame != NULL) {
             using_tmpdir = 1;
          }
       }
#endif
       if (using_tmpdir == 0) {
          perror("FLAM3: opening temporary file");
          return (NULL);
       }
   }
   flam3_print(tmpflame,cp,NULL,flam3_dont_print_edits);
   stringbytes = ftell(tmpflame);
   fseek(tmpflame,0L, SEEK_SET);
   genome_string = (char *)calloc(stringbytes+1,1);
   if (stringbytes != fread(genome_string, 1, stringbytes, tmpflame)) {
       perror("FLAM3: reading string from temp file");
   }
   fclose(tmpflame);

   if (using_tmpdir)
      unlink(tmpnam);

   return(genome_string);
}

完整的来源可以在这里找到: https://code.google.com/p/flam3/source/browse/trunk/src/flam3.c

我希望有人能够解释为什么程序无法在生产环境中渲染图像。 我的想法是朝着具有权限或类似安全问题的方向发展。

如有任何帮助,我们将不胜感激。

<小时/>

更新:

<小时/>

我试图找出 tmp_path 可能是什么。但我对此感到相当挣扎。尽管我有源代码,但我无法编译有问题的程序。 作为替代方案,我创建了一个小型 C++ 程序来模拟存在问题的部分。把它不输出任何东西到标准输出:

#include "stdafx.h"
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
#pragma warning(push)
#pragma warning(disable: 4996) //4996 for _CRT_SECURE_NO_WARNINGS equivalent

    cout << "Entering debugger\n";

    FILE *tmpflame;
    long stringbytes;
    char *genome_string;

    int using_tmpdir = 0;
    char *tmp_path;
    char tmpnam[256];

    // deprecated code here
    tmpflame = tmpfile();

    //strcpy (tmpflame->_tmpfname,tmpnam);
    if (NULL==tmpflame) {
#ifdef _WIN32       
        cout <<"Entering branch 1\n";

        // This might be a permissions problem, so let's try to open a
        // tempfile in the env var TEMP's area instead
        tmp_path = getenv("TEMP");

        if (tmp_path != NULL) {
            cout <<"Entering branch 2\n";

            strcpy(tmpnam, tmp_path);
            strcat(tmpnam, "\\fr0st.tmp");
            tmpflame = fopen(tmpnam, "w+");
            if (tmpflame != NULL) {
                cout <<"Entering branch 3\n";
                using_tmpdir = 1;
            }
        }
#endif
    }
    cout <<tmpflame->_tmpfname;
    return 0;
#pragma warning(pop)

}

最佳答案

对。 结果发现问题是权限问题。不知何故,exe 文件没有获得正确的凭据。 我通过提升 worker 角色来解决这个问题: 添加<Runtime executionContext="elevated" /><WorkerRole> 内的 .csdef

关于c# - Azure辅助角色中的程序执行可以在本地模拟器中运行,但不能在云中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19841962/

相关文章:

Azure Web App Easy Auth 处理 (/.auth/me)

c# - 表达式树 : Binary operator not defined for types

c# - 仅为特定类型参数重命名通用类型的 xml 元素

c++ - 正确使用 boost 区域设置生成器

javascript - azure-graph Users.get(principalID) 抛出 Request_ResourceNotFound

Azure - 资源组和关联组之间的关系

c# - Azure Web 应用程序。免费比基本版和标准版更快?

c# - 无法将 C# 可执行文件连接到远程计算机上的数据库文件

c++ - 什么时候用 "class_name obj_name = func()"替换 "class_name obj_name{func()}"有意义?

c++ - 无论如何要弄清楚什么STL头文件没有被直接包含?