首页 > 解决方案 > 从 azure app service 执行进程

问题描述

我正在运行一个进程以使用来自 proto 文件的 GRPC 工具生成 c# 类。该代码在我的开发机器上运行良好,但一旦部署在 azure 上,进程运行但返回 aExitCode = -1073740791并且输出为空字符串。

我已经记录了我执行的命令,如果我尝试在Kudu控制台中执行它工作正常并且 c# 文件按预期生成。

该命令如下所示:

Tools\bin\tools\windows_x86\protoc.exe 
-ID:\local\LocalAppData\GrpcTester\0969261f-bfa7-45a8-bba1-7e1ccd3818e7\protos 
--csharp_out=D:\local\LocalAppData\GrpcTester\0969261f-bfa7-45a8-bba1-7e1ccd3818e7\csharpfiles 
--grpc_out=D:\local\LocalAppData\GrpcTester\0969261f-bfa7-45a8-bba1-7e1ccd3818e7\csharpfiles 
--plugin=protoc-gen-grpc="Tools\bin\tools\windows_x86\grpc_csharp_plugin.exe" 
D:\local\LocalAppData\GrpcTester\0969261f-bfa7-45a8-bba1-7e1ccd3818e7\protos\mobile_backend.proto
private bool GenerateGRPCCSharpFiles(TestProject testProject)
        {
            bool succes = false;
            var outputFolder = WorkspaceManager.GetProjectSubFolder(testProject.Id.ToString(), WorkspaceManager.CSharpFilesPath);
            var protoFilesFolder = WorkspaceManager.GetProjectSubFolder(testProject.Id.ToString(), WorkspaceManager.ProtosPath);


            // Install tools
            RequireTools().Wait();

            var protoc = ProtocPath();
            var plugin = ProtocPluginPath();
            logger.LogDebug($"GenerateGRPCCSharpFiles : protoc: {protoc}");
            logger.LogDebug($"GenerateGRPCCSharpFiles : plugin: {plugin}");

            //string protocol = Path.Combine(protoFilesFolder, protoFiles.FirstOrDefault().FileName);
            string protocol = Directory.GetFiles(protoFilesFolder).FirstOrDefault();

            var command = new string[]
            {
                $"-I{protoFilesFolder}",
                $"--csharp_out={outputFolder}",
                $"--grpc_out={outputFolder}",
                $"--plugin=protoc-gen-grpc=\"{plugin}\"",
                protocol,
            };


            try
            {
                using (Process process = new Process())
                {
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.FileName = protoc;
                    process.StartInfo.Arguments = string.Join(' ', command);
                    process.StartInfo.CreateNoWindow = true;
                    process.StartInfo.RedirectStandardOutput = true;

                    process.Start();
                    process.WaitForExit();

                    using (var streamReader = new StreamReader(process.StandardOutput.BaseStream))
                    {
                        var response = streamReader.ReadToEnd();
                        logger.LogDebug($"GenerateGRPCCSharpFiles: Completed output: {response.ToString()}");
                    }

                    succes = process.ExitCode == 0;

                };
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return succes;
        }

标签: processgrpcazure-web-app-serviceexecute

解决方案


这与应用服务沙盒有关。按照获取更多信息。


推荐阅读