/* This example shows how to launch another script that runs * "detached". ie, The child script runs in a separate * process from the main script. The child script therefore * does not prevent the main script from running until the * child script ends. Nor does the child script end when the * main script ends. And the child script does not share * any variables, subroutines, condition traps, etc, with * the main script. It's as if the child script was manually * launched by the enduser, and is completely independent * from the main script. */ OPTIONS "WINFUNC NOSOURCE C_CALL" NUMERIC DIGITS 10 /* ============== FUNCDEF stuff ============ */ DO /* Register ShellExecute() */ FUNCDEF('ShellExecute', 'void, void, str, str, str, str, 32u', 'shell32') CATCH FAILURE CONDITION("M") RETURN END /* ************** Launch the child.rex script ************** */ SAY "This is the parent script, launching the child script." /* Here we launch a child script named "child.rex". We launch * it by calling ShellExecute() and specifying an "open" * operation. A REXX script is actually considered a "Document" * (ie, data file) by the Windows operating system. And when * you open a Document, then Windows automatically runs the * application associated with the Document. So, if RXLAUNCH.EXE * is associated with REXX files, then RXLAUNCH.EXE is launched * and passed the name of our REXX script to run. ShellExecute() * will return as soon as RXLAUNCH.EXE starts up. * * The first arg is the handle to some open window that you * want ShellExecute to use if it needs to display a message * box. Omit this arg to use the desktop. * * The second arg is the operation. It must be either "open" (to * launch an application or open a Document), "print" (to print * a Document, such as printing a text file named "myfile.txt"), * or "explore" (to explore a Document). If omitted, it defaults * to "open". * * The third arg is the name of the executable or Document to * open, print, or explore. ShellExecute can open an executable * or a Document. ShellExecute can print a Document. You can * specify the full path name, such as "c:\program files\reginald\rxlaunch.exe". * * The fourth arg is used only if you specified the name of an * executable (ie, not a Document) as the third arg. The fourth * arg is any arguments you wish passed to the executable, such * as a Document name, etc, just as you may type them at a * command prompt. * * The fifth arg is the name of the directory you want to be * used as the default directory. Omit this if you wish the * same directory as the exe/Document. * * The sixth arg is used only if you specified the name of an * executable (ie, not a Document) as the third arg. The sixth * arg is one of the following numeric values: * * 0 = Hides the exe's window and activates another window. * 1 = Activates and displays the exe's window at normal size. You should * specify this when displaying the window for the first time. * 9 = Activates and displays the exe's window at normal size. If the window * was previously minimized or maximized, it is restored its original size and * position. You should specify this when restoring a previously minimized window. * 4 = Displays the exe's window in its most recent size and position. The * currently active window remains active. * 2 = Activates the exe's window and displays it minimized. * 7 = Displays the exe's window as a minimized window. The currently active * window remains active. * 6 = Minimizes the exe's window and activates the next top-level window in * the Z order. * 3 = Activates the exe's window and displays it maximized. * 5 = Activates the exe's window and displays it in its current size and position. * 8 = Displays the window in its current state. The active window remains active. * 10 = Activates the window and displays it however the enduser has set * the properties for the exe. * * If ShellExecute() succeeds, it returns the handle to the new process. If it * fails, then it returns a value of 32 or less. */ result = ShellExecute(, , 'child.rex', , , 1) IF result <= 32 THEN DO SELECT WHEN result = 0 | result = 8 THEN SAY "The operating system is out of memory or resources." WHEN result = 2 THEN SAY "The specified file was not found." WHEN result = 3 THEN SAY "The specified path was not found." WHEN result = 5 THEN SAY "The operating system denied access to the specified file." WHEN result = 11 THEN SAY "The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)." WHEN result = 26 THEN SAY "A sharing violation occurred." WHEN result = 27 THEN SAY "The filename association is incomplete or invalid." WHEN result = 28 THEN SAY "The DDE transaction could not be completed because the request timed out." WHEN result = 29 THEN SAY "The DDE transaction failed." WHEN result = 30 THEN SAY "The DDE transaction could not be completed because other DDE transactions were being processed." WHEN result = 31 THEN SAY "There is no application associated with the given filename extension." WHEN result = 32 THEN SAY "The specified dynamic-link library was not found." OTHERWISE SAY "ShellExecute failed." END EXIT END /* ******** Carry on with this script while child.rex is running */ SAY "Press any key to end the parent..." PULL RETURN