2017-07-27 38 views
0

実行可能ファイルabcd.exeがあります(多くの.dllファイルを含む/マージされています)。 abcd.exe用のAzure関数を作成し、Azure Cloud関数で実行することはできますか?Azure関数で.exe実行可能ファイルを実行する

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)を持っていませんが、それは数学と科学のアプリケーションであり、それはABCDの内側にマージされ、多くの.dllから依存しています。 EXE。

答えて

5

ありがとうそれはabcd.exeためAzureの機能を作成し、Azureのクラウド機能でそれを実行することは可能ですか?

はい、Azure関数アプリで.exeファイルをアップロードして実行できます。私は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ファイルが

enter image description here

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ファイルから挿入されて見つけることができます。 enter image description here

+0

それは問題なく機能をコンパイルされたが、それは(このケースでは、私は任意の結果を持っていない) 2017-08-01T14を実行していない:50 :00.009機能が起動しました(Id = ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :50:00.208 C#タイマートリガ関数の実行日時:8/1/2017 2:50:00 PM 2017-08-01T14:50:00.208関数が完了しました(成功、Id = ########### #########、Duration = 200ms) – Ves

1

フレッドありがとうございました。さて、マイナーな変更を加えれば、アプリケーションはコンパイルされ実行されています。

アプリケーションにいくつかのマイナーな修正:

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 [email protected]"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}"); 
} 
+0

こんにちは@Ves、私の返信が役に立ちましたら、それを他の人がすぐにこのスレッドを見つけて似たように解決するのに役立つ回答(または投票)としてマークすることができます問題。 –

+0

こんにちは@Fred、あなたの返信は役に立ちました。私は投票しました。私は新しいユーザーで、このメッセージが表示されます:フィードバックありがとう!評判が15未満の人の投票が記録されますが、公開されている投稿のスコアは変更されません。 – Ves

関連する問題