简体   繁体   English

从Inno Setup中运行的命令行应用程序获取输出

[英]Getting output from running command line app in Inno Setup

The scenario is that we wrote a console application, that we want to call during an Inno Setup and read its output. 场景是我们编写了一个控制台应用程序,希望在Inno Setup期间调用它并读取其输出。 In contrast to this problem it is necessary to read this output from Inno Setup while the other program is still running. 相对于此问题 ,有必要在其他程序仍在运行时从Inno Setup读取此输出。 The output shall contain progress information of the runnig application (double or int values), that we want to display in Inno with the ProgressGauge. 输出将包含我们要使用ProgressGauge在Inno中显示的runnig应用程序的进度信息(双精度或整数值)。 The app is a simple executable written in C# and can run from some seconds to several minutes. 该应用程序是用C#编写的简单可执行文件,可以运行几秒钟到几分钟。

Is this possible and if yes, can it be done without freezing the GUI of Inno Setup (as the application can take some time)? 这是否可能,如果可以,是否可以在不冻结Inno Setup的GUI的情况下完成(因为该应用程序可能需要一些时间)?

With TLama pointing to the progress bar messages I was able to solve the problem. 通过TLama指向progress bar messages我能够解决问题。

At first I needed to pass the progress bar handle from Inno to my C# app. 首先,我需要将进度条句柄从Inno传递到C#应用程序。 For this I created a function that would return me the int-pointer as a string 为此,我创建了一个函数,该函数会将int指针作为字符串返回给我

function GetProgressHandle(Param: String): String;
begin
  Result := Format('%d',[WizardForm.ProgressGauge.Handle]);
end;

and use it in the Run-section when calling my app: 并在调用我的应用程序时在“运行”部分中使用它:

[Run]
Filename: "{app}\myApp.exe"; Parameters: "{code:GetProgressHandle}"; ....

In C# I read the int-pointer from the console arguments and use it to create an IntPtr : 在C#中,我从控制台参数中读取了int指针,并使用它来创建IntPtr

IntPtr pointer = new IntPtr(Int32.Parse(args[0]));

To send the messages to the progress bar I imported user32.dll and re-defined the needed constants, that normally can be found in commctrl.h: 要将消息发送到进度条,我导入了user32.dll并重新定义了所需的常量,这些常量通常可以在commctrl.h中找到:

[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

public const uint PBM_SETRANGE = 0x401;
public const uint PBM_SETPOS = 0x402;

Finally, I could set the range of the progress bar from 0 to max and a specific position pos with 最后,我可以设置从0进度条到最大和特定位置pos与范围

PostMessage(pointer, PBM_SETRANGE, (IntPtr)0, (IntPtr)(max << 16));    
PostMessage(pointer, PBM_SETPOS, (IntPtr)pos, (IntPtr)0);

NOTE : Changing the progress bar position didn't seem to update the Inno Setup Window immediately. 注意 :更改进度条的位置似乎并不能立即更新Inno Setup窗口。 I tested it by increasing the position every 500 ms but there where noticeable differences (pauses were more in the range of ca. 0.2-0.8 ms). 我通过每500毫秒增加一次位置来测试它,但是在那儿有明显的差异(暂停在0.2到0.8毫秒范围内更大)。 For my case it is not important that changing the progress bar is accurately timed, but I assume that the Inno Setup window can be updated in a similar way (with the specific handle and a different message-constant) for those who need this. 就我而言,准确地更改进度条的时间并不重要,但我认为可以为需要此操作的人以类似的方式(使用特定的句柄和不同的消息常量)来更新Inno Setup窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM