{***********************************************************************}
{									}
{ __DOSExPgm  Execute a DOS command					}
{									}
{ procedure __DOSExPgm(CmdLine : string; var ErrorCode : word); 	}
{									}
{	      CmdLine	The command line string to pass to DOS for	}
{			execution.					}
{	      ErrorCode The returned error status code; values are:	}
{			0 - COMMAND successfully loaded executed.	}
{			2 - command.com could not be found.		}
{			3 - The path specified in the COMSPEC=		}
{			    could not be found. 			}
{			8 - Insufficient memory to load the second	}
{			    copy of COMMAND				}
{		       18 - command.com could not be found		}
{		       98 - COMSPEC= could not be found in the environ- }
{			    ment.					}
{			If DOS version 3.0 or later is used, a call to	}
{			__RetErUtl can be made to return more detail	}
{			on errors 2 through 8.				}
{									}
{ Description __DOSExPgm searches the environment for COMSPEC=, and	}
{	      using that parameter, loads a secondary copy of the	}
{	      command line interpreter, COMMAND, using	__ExecPgm.	}
{									}
{	      The specified command line is passed to COMMAND		}
{	      for execution.  Note that the error codes returned re-	}
{	      flect the success with which COMMAND was loaded rather	}
{	      than any success or failure with which the command	}
{	      executed. 						}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

procedure __DOSExPgm(CmdLine : string; var ErrorCode : word);

  var
    FileSpec   : SearchRec;
    ComSpec    : _Path;
    ExecCmd    : string;

  begin {__DOSExPgm}

    ComSpec := __GetEnUtl('COMSPEC=');
    if (Length(ComSpec) = 0) then
       begin
	 ErrorCode := 98;	       { COMSPEC= not in the environment}
	 Exit
       end;

    { Now make sure command.com is where COMSPEC= says it is.  If	}
    { FindFirst  cannot find it, report the error and return.		}

     FindFirst(ComSpec,23,FileSpec);
     if (DosError <> 0) then
	begin
	  ErrorCode := DosError;
	  Exit
	end;

    { Finally construct the command line to be passed to COMMAND	}
    { and make a call to __ExecPgm.					}

    ExecCmd := '/C '+ CmdLine;
    __ExecPgm (Comspec,ExecCmd,TRUE,ErrorCode)

  end;	{__DOSExPgm}
