4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 2004

LAUNCH EXTERNAL PROCESS (fileName{; inputStream{; outputStream{; errorStream}}})

fileNameStringFile path and arguments of file to launch
inputStreamString | BLOBInput stream (stdin)
outputStreamString | BLOBOutput stream (stdout)
errorStreamString | BLOBError stream (stderr)

Warning: This command is designed for advanced users.


The LAUNCH EXTERNAL PROCESS command allows you to launch an external process from 4D under Mac OS X and Windows.

Under Mac OS X, this command provides access to any executable application that can be launched from the Terminal.

Note: For 4D Pack users, this command has the same functions (plus expanded features) as the AP_Sublaunch command.

Pass the fixed file path of the application to execute, as well as any required arguments (if necessary), in the fileName parameter.

Under Mac OS X, you can also pass the application name only; 4D will then use the PATH environment variable to locate the executable.

Warning: This command can only launch executable applications; it cannot execute instructions that are part of the shell (command interpreter). For example, under Mac OS it is not possible to use this command to execute the echo instruction or indirections.

The inputStream parameter (optional) contains the stdin of the external process. Once the command has been executed, the outputStream and errorStream parameters (if passed) return respectively the stdout and stderr of the external process. You can use BLOB parameters instead of strings if you manage text data of a size greater than 32 KB or binary data (such as pictures).

Note: If you use the _4D_OPTION_BLOCKING_EXTERNAL_PROCESS environment variable via the SET ENVIRONMENT VARIABLE command (asynchronous execution), the outputStream and errorStream parameters are not returned.

Examples under Mac OS X

The following examples use the Mac OS X Terminal available in the Application/Utilities folder.

1. To change permissions for a file (chmod is the Mac OS X command used to modify file access):

   LAUNCH EXTERNAL PROCESS ("chmod +x /folder/myfile.txt")

2. To edit a text file (cat is the Mac OS X command used to edit files). In this example, the full access path of the command is passed:

   LAUNCH EXTERNAL PROCESS ("/bin/cat /folder/myfile.txt";input;output)

3. To get the contents of the "Users" folder (ls -l is the Mac OS X equivalent of the dir command in DOS):

   LAUNCH EXTERNAL PROCESS("/bin/ls -l /Users";$In;$Out)

4. To launch an independent "graphic" application, it is preferableb to use the open system command (in this case, the LAUNCH EXTERNAL PROCESS statement has the same effect as double-clicking the application): 

   LAUNCH EXTERNAL PROCESS("open /Applications/")

Examples under Windows

5. To open NotePad:


6. To open Notepad and open a specific document:

   LAUNCH EXTERNAL PROCESS ("C:\\WINDOWS\\notepad.exe C:\\Docs\\new folder\\res.txt")

7. To launch the Microsoft® Word® application and open a specific document (note the use of the two ""):

   $mydoc:="C:\\Program Files\\Microsoft Office\\Office10\\WINWORD.EXE \"C:\\Documents and 
                        Settings\\Mark\\Desktop\\MyDocs\\New folder\\test.xml\""

8. To execute a Perl script (requires ActivePerl):

   SET ENVIRONMENT VARIABLE("myvariable";"value")
   LAUNCH EXTERNAL PROCESS ("D:\\Perl\\bin\\perl.exe D:\\Perl\\eg\\cgi\\";$input;$output)

9. To launch a command with the current directory and without displaying the console:


10. To allow the user to open an external document on Windows:

   $docname:=Select document("";"*.*";"Choose the file to open";0)
      LAUNCH EXTERNAL PROCESS("cmd.exe /C start \"\" \""+document+"\"")
   End if

See Also


System Variables or Sets

If the command has been executed correctly, the system variable OK is set to 1. Otherwise (file not found, insufficient memory, etc.), it is set to 0.

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next