我有一个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)
}
答案 0 :(得分:2)
右。
问题原来是一个许可问题。不知何故,exe文件没有获得正确的凭据。
我通过提升工作者角色来解决它:
将<Runtime executionContext="elevated" />
添加到<WorkerRole>