How to run an executable program?

This script illustrates how to run an external program or a program that was compiled inside your application. For instance, you would like to launch a program that you ship with your application.

Running an external program file

We use the internal HEScript function named RunAProgram to execute a program. We only need to know the path to the program file we want to launch. Fortunately ExeOutput for PHP has a global variable named HEPublicationPath pointing to the path of the folder that contains the application's exe file.

Script example:

procedure RunTutor;
EbookPath, MyProgram: String;
EbookPath := GetGlobalVar("HEPublicationPath", "");
MyProgram := EbookPath + "hehvdemo.exe";
RunAProgram(MyProgram, "", EbookPath, false, SW_SHOWNORMAL);

First we get the path to our application stored into the EbookPath variable. Then we add the filename of our executable program and we pass the result to the RunAProgram function.

Run a program that was compiled in the application

You can include the program file directly into your application .exe. In that case you need to extract the program file before running it: use the heopenit special protocol, or the following code:

procedure RunACompiledProgram;
MyProgram: String;
MyProgram := UnpackTemporaryResource("programfilename.exe");
RunAProgram(MyProgram, "", ExtractFilePath(MyProgram), false, SW_SHOWNORMAL);

This code uses the UnpackTemporaryResource internal function that extracts a compiled file from the publication to a temporary location. Then you just need to execute the file.

Introduction to Scripting

Using the Script Manager

Script Function Reference