Admin Production ni-theme
Current Publication

LaunchExecutable

LabWindows/CVI

LaunchExecutable

int LaunchExecutable (char filename[]);

Purpose

Note Note  This function has been superseded by LaunchExecutableEx.

Starts running a program and returns without waiting for the program to exit. The executable can be a DOS or Windows executable, including *.exe, *.com, *.bat, and *.pif files.

Note   If you want to wait for the program to exit, use the systemsystem function in the ANSI C Library. If you want to monitor whether the launched executable has terminated, use LaunchExecutableEx.

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

.exe, .com, and .bat DOS programs use the settings in _default.pif in the Windows directory when running. You can change settings such as priority and display options by editing _default.pif or by creating another .pif file. For more information about creating and editing .pif files, refer to www.msdn.com.

If you need to execute a command built into cmd.exe, such as copy or dir, you can call LaunchExecutable with the following command:

cmd.exe /c command args

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

LaunchExecutable ("cmd.exe /c copy c:\\temp\\file.tmp c:\\tmp");

For more information about cmd.exe, refer to www.msdn.com.

Parameters

Input
Name Type Description
filename char [] 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 function call launches the Edit program with the file file.dat:

LaunchExecutable ("edit.com c:\\file.dat");

Return Value

Name Type Description
result int 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 The directory name is invalid.
-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.
-216 The bitness of the application is incompatible with this operating system.
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.

Additional Information

Library: Utility Library

Include file: utility.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Examples

Refer to the following examples that use the LaunchExecutable function:

  • apps\atedemo\atedemo.cws

    Open example
  • apps\helpworkshop\workshop.cws

    Open example