Start an OS/2 program synchronously

[Autolink] Menu

Some PM programs (for example VIEW.EXE and NOTES.EXE) start asynchronously if called from a REXX program. Use the following code to start one of these programs and wait until it ends (You can also use this technique for a simple Process controller in REXX; see also Start a Windows program synchronously and StartDOS):

 
/* sample code to start an OS/2 program synchronously                 */

                    /* load the necessary REXXUTIL function(s)        */
  call rxFuncAdd "SysSleep", "REXXUTIL", "SysSleep"

                    /* name of the "semaphore" file                   */
                    /* Note: If you want to run this program in       */
                    /*       separate sessions at the same time, use  */
                    /*       a routine that lets you get a unique     */
                    /*       name for a temporary file, to get a      */
                    /*       unique name for your semaphore files.    */
                    /*       (for example                             */
                    /*       Get a name for a temporary file)         */
  SemFile = "TEST.SEM"

                    /* start the program and redirect STDOUT into the */
                    /* "semaphore" file                               */
                    /* Note that this technique does not work    3.20 */
                    /* if there is already an instance of the    3.20 */
                    /* view program running!!!                   3.20 */

  "view cmdref.inf >" || semFile

                    /* wait until the program ends                    */
  do until stream(  semFile, "c", "OPEN READ" ) = "READY:"
    call SysSleep 1
  end /* do until ... */

                    /* close and delete the "semaphore" file          */
  call stream semFile, "c", "CLOSE"
  "del " semFile "2>NUL 1>NUL"
exit 0

Note that this technique does not work if there is an instance of the program to start already running and if the call of the program only passes the parameter to the running instance. This is true for view.exe, for example.


[Back: Starting other programs in REXX programs]
[Next: Start a Windows program synchronously]