# LaunchExecutable

int LaunchExecutable (char fileName[]);

## Purpose

Starts running a program and returns without waiting for the program to exit.

| Note If you want to wait for the program to exit, use the system function in the ANSI C Library.

The program must be an actual executable; that is, you cannot launch commands intrinsic to a command interpreter.

The executable can be either a DOS or Windows executable, including *.exe, *.com, *.bat, and *.pif files.

.exe, .com, and .bat DOS programs use the settings in _default.pif (in the Windows directory) when running. You can change their priority, display options, and so on., by editing _default.pif or by creating another .pif file. Refer to your Microsoft Windows documentation for help on creating and editing .pif files.

If you need to execute a command built into command.com such as copy, dir, and others, you can call LaunchExecutable with the following command:

command.com /C DosCommand args

where DosCommand is the shell command you want to execute. For example, the following command string copies file.tmp from the temp directory to the tmp directory:

command.com /C copy c:\\temp\\file.tmp c:\\tmp

| Note If you want to monitor whether the launched executable has terminated, use LaunchExecutableEx.

## Parameters

Input
Name | Type | Description
fileName | string | Pathname of executable file to run. If the program is not in one of the directories specified in the PATH environment variable, you must specify the full path. The path can include arguments to pass to the program. If the program is a .pif, .bat, or .com file, you must include the extension in the pathname. For example, under Windows, the following command string launches the Edit program with the file file.dat: c:\\dos\\edit.com c:\\file.dat

## Return Value

Name | Type | Description
result | integer | Result of the operation. Error codes vary, depending on whether you have a Windows or Linux application.
Windows Error Codes
Code | Description
0 | Command was successfully started.
-1 | System was out of memory, executable file was corrupt, or relocations were invalid.
-2 | A DLL required by the executable cannot be found.
-3 | File was not found.
-4 | Path was not found.
-6 | Attempt was made to dynamically link to a task, or there was a sharing or network-protection error.
-7 | Library required separate data segments for each task.
-9 | There was insufficient memory to start the application.
-11 | Windows version was incorrect.
-12 | Executable file was invalid. Either it was not a Windows application or there was an error in the .exe image.
-13 | Application was designed for a different operating system.
-14 | Application was designed for MS-DOS 4.0.
-15 | Type of executable file was unknown.
-16 | You made an attempt to load a real-mode application developed for an earlier version of Windows.
-17 | You made an attempt to load a second instance of an executable file that contains multiple data segments that were not marked read only.
-19 | The operating system returned an unknown error code.
-20 | Attempt was made to load a compressed executable file. You must decompress the file before you can load it.
-21 | DLL file was invalid. One of the DLLs required to run this application was corrupt.
-22 | Application requires Windows 32-bit extensions.
Linux Error Codes
0 | Command successfully started.
-1 | Launching the executable would exceed the operating system limit on the total number of processes under execution or the total number of processes per user.
-2 | Insufficient swap space for the new process.
-3 | vfork failed for unknown reason.
-4 | Search permission is denied for a directory listed in the path prefix of the new process image file, the new process image file denies execution permission, or the new process image file is not a regular file.
-5 | The length of the pathname of filename or an element of the environment variable PATH prefixed to a filename exceeds PATH_MAX, or a pathname component is longer than NAME_MAX while _POSIX_NO_TRUNC is in effect for that file. Refer to the man page for pathconf(2V).
-6 | One or more components of the pathname of the new process image file do not exist.
-7 | A component of the path prefix of the new process image file is not a directory.
-8 | Number of bytes that the new process-image-argument list and the environment list use is greater than ARG_MAX bytes. Refer to the man page for sysconf(2V).
-9 | New process image file has the appropriate access permission but is not in the proper format.