在Azure Function中运行.exe可执行文件
我有可执行文件abcd.exe(它包含/合并了许多.dll)。 是否可以为abcd.exe创建Azurefunction并在Azure云function中运行它?
abcd.exe应用程序:
System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; **startInfo.Arguments = "/C abcd.exe";** process.StartInfo = startInfo; process.Start();
abcd.exe应用程序没有UI(GUI),但它是数学和科学应用程序,它依赖于许多.dll合并在abcd.exe中。
谢谢
是否可以为abcd.exe创建Azurefunction并在Azure云function中运行它?
是的,我们可以上传.exe文件并在Azure Function应用程序中运行它。 我创建了一个TimerTrigger函数应用程序,并运行一个.exe,它将记录插入到这个函数应用程序的数据库中,这对我来说很好。
function.json
{ "bindings": [ { "name": "myTimer", "type": "timerTrigger", "direction": "in", "schedule": "0 */1 * * * *" } ], "disabled": false }
run.csx
using System; public static void Run(TimerInfo myTimer, TraceWriter log) { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = @"D:\home\site\wwwroot\TimerTriggerCSharp1\testfunc.exe"; process.StartInfo.Arguments = ""; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); string output = process.StandardOutput.ReadToEnd(); string err = process.StandardError.ReadToEnd(); process.WaitForExit(); log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); }
将.exe文件上传到Function app文件夹
我的.exe程序中的主要代码
SqlConnection cn = new SqlConnection("Server=tcp:{dbserver}.database.windows.net,1433;Initial Catalog={dbname};Persist Security Info=False;User ID={user_id};Password={pwd};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"); cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = "insert into [dbo].[debug]([Name]) values('test')"; cmd.ExecuteNonQuery(); cn.Close();
查询数据库,我可以找到从我的.exe文件中插入的测试记录。
弗雷德非常感谢你的帮助。 现在,通过稍加修改,应用程序正在编译和运行。
对应用程序的一些小修改:
using System; using System.Diagnostics; using System.Threading; public static void Run(TimerInfo myTimer, TraceWriter log) { System.Diagnostics.Process process = new System.Diagnostics.Process(); string WorkingDirectoryInfo =@"D:\home\site\wwwroot\TimerTriggerCSharp1"; string ExeLocation = @"D:\home\site\wwwroot\TimerTriggerCSharp1\MyApplication.exe"; Process proc = new Process(); ProcessStartInfo info = new ProcessStartInfo(); try { info.WorkingDirectory = WorkingDirectoryInfo; info.FileName = ExeLocation; info.Arguments = ""; info.WindowStyle = ProcessWindowStyle.Minimized; info.UseShellExecute = false; info.CreateNoWindow = true; proc.StartInfo = info; proc.Refresh(); proc.Start(); proc.WaitForInputIdle(); proc.WaitForExit(); } catch { } log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); }
- Azure WebSites或Azure云服务上的MVC4 API :’System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption’
- 在Azure Cosmos DB中使用REST进行CRUD操作
- Azure Web App跟踪日志未显示在日志中
- 如何通过AADvalidationAzure服务管理请求
- 我们如何跟踪azure文件存储文件夹是否更新?
- Stackexchange.Redis超时和socketfailures
- 将最多100,000条记录插入DocumentDB的最快方法
- 交换Azure Web App部署槽会注销ASP.NET Core RC2中的所有用户
- 多语言网站:Azure部署的行为与localhost不同