我有一些奇怪的行为。
基本上,我的代码在本地计算机上运行良好,当我使用远程桌面登录该服务时,我可以使用与我在 C# 中给出的完全相同的参数从命令行运行 exe,没有任何问题。它运行完美。
我想知道是否存在任何限制或权限阻止 exe 在 Azure WorkerRole 中运行?或者代码中可能存在问题,导致其无法在 WorkerRole 中正常运行,但仅限于 Azure?
- exe 不会重定向任何 stdout 或 stderr,因此出现错误时我无法读取任何输出。我本地也出现这种情况。
- exe 设置为复制到 azure 上应用程序的构建目录。 exe 存在于指定的路径中(我已经尝试了 File.Exists 以及 pdf 所在的位置,只是为了确定)
- 我尝试将
startInfo.CreateNoWindow
设置为true
以查看是否可以查看远程桌面中运行的进程,但我不能。我假设 WorkerRole 和远程桌面是计算机上的不同用户。
这是我的代码:
LocalResource tempStorage = RoleEnvironment.GetLocalResource("TempStorage");
string tempDir = tempStorage.RootPath;
string tempName = Guid.NewGuid().ToString();
string tempFile = Path.Combine(tempDir, tempName + ".pdf");
string saveFile = tempName + ".html";
string exeDir = Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + @"\", @"approot\Resources\");
File.WriteAllBytes(tempFile, fileBytes);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Path.Combine(exeDir, "pdf2htmlEX.exe");
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = exeDir;
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = String.Format("--zoom 1.5 --dest-dir \"{0}\" \"{1}\" \"{2}\"", tempDir, tempFile, saveFile);
startInfo.CreateNoWindow = true;
using (Process proc = Process.Start(startInfo))
{
proc.WaitForExit(30000);
}
// saveFile does not exist here or any time after the process exists
使用该项目的exe。太棒了:https://github.com/coolwanglu/pdf2htmlEX
编辑:找到一些日志信息...
Faulting application name: pdf2htmlEX.exe, version: 0.0.0.0, time stamp: 0x520bb881
Faulting module name: pdf2htmlEX.exe, version: 0.0.0.0, time stamp: 0x520bb881
Exception code: 0xc0000005
Fault offset: 0x0013a6e4
Faulting process id: 0x9cc
Faulting application start time: 0x01ceaf4109e78f34
Faulting application path: C:\Resources\directory\96bf7ddee08d45a8883fe2a603131842.WorkerRole.TempStorage\pdf2htmlEX.exe
Faulting module path: C:\Resources\directory\96bf7ddee08d45a8883fe2a603131842.WorkerRole.TempStorage\pdf2htmlEX.exe
Report Id: 48260a60-1b34-11e3-93ef-00155d4334a7
Faulting package full name:
Faulting package-relative application ID:
进程在预处理所有页面后停止,然后在工作时失败。如果我运行“DebugView”我得到:
[1356] Invalid parameter passed to C runtime function.
[1356] Error -
[1356] RtlWerpReportException failed with status code :-1073283067. Will try to launch the process directly
[1356]
也许这是应用程序的一个错误? (也许不应该写入内存)我仍然不明白为什么这只在 WorkerRole 中失败。
最佳答案
我会推荐几种不同的方法来解决此问题。
- Procmon。它会显示您尝试在某处写入临时文件时是否被拒绝访问。
- 将 WinDBG 附加到 pdf2htmlEX.exe 并查看它是否引发任何异常。
#2 的技巧是将 WinDBG 附加到 Azure 中运行的进程是很棘手的。请参阅http://blogs.msdn.com/b/kwill/archive/2013/08/26/azuretools-the-diagnostic-utility-used-by-the-windows-azure-developer-support-team.aspx了解在 Azure VM 上获取 Procmon 和 WinDBG 的快速简便方法,以及将 WinDBG 附加到进程的方法。
关于azure - Azure WorkerRole 中的意外 Process.Start 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18710423/