KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using Launch External Process to run applications asynchronously
PRODUCT: 4D | VERSION: 11.4 | PLATFORM: Win
Published On: July 1, 2009

The command Launch External Process can be used to open Microsoft Office applications, among other things. However, opening certain applications such as Excel can cause 4D to become unresponsive until the application is closed.

For example, when running the following code (using Excel 2003 on Windows XP), the Launch External Process command will open Excel, but the Alert command will not be executed until Excel has been closed:

C_TEXT($command)

$command:="C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE"
LAUNCH EXTERNAL PROCESS($command)
ALERT("Done")


In this scenario, 4D is not continuing to execute the method, because the the Launch External Process command is executing synchronously. However, the Launch External Process command can be set to execute asynchronously, allowing 4D to continue executing the rest of the method regardless of whether the Launch External Process command has finished executing.

The Launch External Process command can be made to execute asynchronously by adding the SET ENVIRONMENT VARIABLE command and specifying the "_4D_OPTION_BLOCKING_EXTERNAL_PROCESS" variable name with the value of "false".

Here is the code from above, with the added command:

C_TEXT($command)

$command:="C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE"
SET ENVIRONMENT VARIABLE("_4D_OPTION_BLOCKING_EXTERNAL_PROCESS";"false")
LAUNCH EXTERNAL PROCESS($command)
ALERT("Done")


In this version of the code, the Launch External Process command will open Excel, and the Alert command will be immediatly displayed.

Commented by Thomas Fitch on July 2, 2009 at 1:37 PM
This Tech Tip talks about MS Excel, but it should be valuable for a number of external applications. Any time you want to allow user interface in the process being launched, you will probably want it to also be asynchronous. That way 4D can continue working while the external process is running.

Just keep in mind that if 4D is waiting for a response (if you need an "answer" back from the external process) that you probably do not want to use this feature.