Executing a PC Command from RPG

     h dftactgrp(*no) actgrp('QILE')
     h option(*srcstmt:*nodebugio)

      ********************************************************************
      * PROGRAM NAME - EXCPCCMD - Execute PC Command                     *
      *                                                                  *
      * FUNCTION     - This program accepts a character string in        *
      *                representing a PC command. It many be used to     *
      *                launch a browser from a green-screen application. *
      *                It has a command interface to facilitate using    *
      *                the program from a command line.                  *
      *                                                                  *
      ********************************************************************
      ********************************************************************
      *               PROGRAM INTERFACE SECTION                          *
      *                                                                  *
      *  CALLED BY PROGRAMS: *ANY, command interface EXCPCCMD           *
      *  CALLS PROGRAMS....: QCMDEXC                                     *
      *                      DSPTXTMSG                                   *
      *                                                                  *
      ********************************************************************

     D EXCPCCMD        PR
     D  InString                    256

     D EXCPCCMD        PI
     D  InString                    256

     DExecCmd          PR                  EXTPGM('QCMDEXC')
     D  Command                     256
     D  Length                       15  5

     D DspMsg          PR                  EXTPGM('DSPTXTMSG')
     D  InString                    255
     D  InTitle                      27    options(*nopass)

     D PGMDS         ESDS                  EXTNAME(ISDSTSDS)

     D StrPCcmd        C                   'strpccmd pccmd('
     D apos            S              1    INZ(')')
     D qt              S              1    INZ('''')
     D StrPCO          S            256    INZ('strpco pcta(*no)')
     D ErrorMsg        S            255    INZ('Command not valid')
     D NotStarted      S            255    INZ('PC command environment -
     D                                     not started')
     D L               S             15  5
     D String          S            256
     D Command         S            256
     D qNameO          S            256    varying
      /free

         string = *blanks;

         IF %parms = 1;
             string = inString;
         ENDIF;

         MONITOR;
         l = %len(%trim(strpco));
         ExecCmd( strpco: l );
         ON-ERROR;
            IF msgid <> 'IWS4010';
               ErrorMsg = msgtxt;
               DspMsg(ErrorMsg);
            ENDIF;
         ENDMON;

         MONITOR;
            command = %trim(StrPccmd) + qt + 'START ' + %trim(string) +
               qt + apos + ' ' +  'pause(*no)';
            l = %len(%trim(command));
            ExecCmd( command: l );
         ON-ERROR;
            ErrorMsg = msgtxt;
            DspMsg( ErrorMsg );
         ENDMON;

         RETURN;

      /end-free