簡體   English   中英

為什么我編譯的 AutoIt 腳本在從 C# 調用時無法返回?

[英]Why does my compiled AutoIt script fail to return when called from C#?

我編譯的 AutoIt 腳本本身運行良好,但是當從 C# 調用時,它會運行但沒有完成執行。 我編譯的 C# 代碼:

Process myExe = new Process();
Environment.CurrentDirectory = Path.GetDirectoryName(exeDir); //exeDir is full path of the AutoIt executable directory
ProcessStartInfo StartInfo = new ProcessStartInfo("");
StartInfo.FileName = exeFile; //exeFile is full path of the executable itself
StartInfo.Verb = "runas";
myExe = Process.Start(StartInfo);

它在 AutoIt 代碼中的EnvUpdate()上停止,並最終在其他一些函數上再次停止。 如果我手動運行可執行文件,這些都不會發生。

我從運行這個可執行文件的 C# 啟動了一個批處理文件。 以及CreateNoWindowUseShellExecute組合。 也沒有成功:1)以管理員身份運行 C# 編譯的可執行文件。 2) 使用StartInfo.CreateNoWindowStartInfo.UseShellExecute組合。 3) 從批處理文件運行 AutoIt 可執行文件。 4) 通過批處理文件從 Perl 文件運行 AutoIt 可執行文件。 5) 從 Windows 計划任務運行 AutoIt 可執行文件。 6) 在沒有ProcessStartInfo情況下運行 AutoIt 可執行文件,使用:

myExe = Process.Start("cmd.exe", "/c start /wait " + exeFile);

或者

myExe = Process.Start(exeFile);

這是一個示例 C# 類,用於使用.WaitForExit()對已編譯的 AutoIt 腳本(EXE 文件)進行外部調用,這應該是您的問題:

using System.Configuration;
using System.Diagnostics;

namespace RegressionTesting.Common.ThirdParty
{
    public class ClickAtBrowserPosition
    {
        public static void CallClickAtBrowserPosition(string currentBrowserWindowTitle, int xPosition, int yPosition)
        {
            var pathClickAtBrowserPosition = ConfigurationManager.AppSettings["pathClickAtBrowserPosition"];
            var clickAtBrowserPositionExe = ConfigurationManager.AppSettings["clickAtBrowserPositionExe"];

            var process = new Process();
            var startInfo = new ProcessStartInfo
            {
                WindowStyle = ProcessWindowStyle.Hidden, // don't show the cmd.exe which calls the program
                FileName = "cmd.exe",
                Arguments = @" /C cd " +
                            $@"""{pathClickAtBrowserPosition}"" && {clickAtBrowserPositionExe} ""{currentBrowserWindowTitle}"" {xPosition} {yPosition}"
            };

            process.StartInfo = startInfo;
            process.Start();
            process.WaitForExit(); // wait to finish the execution
        }
    }
}

編譯后的 AutoIt 腳本用於單擊窗口(在本例中為瀏覽器)的相對位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM