Metropoli BBS
VIEWER: execdemo.pas MODE: TEXT (ASCII)
{$M 1024,0,0}
PROGRAM Exec_Demo;
(*By Neil J. Rubenking*)
(*Demonstrates the use of new TP 5.0 routines *)
(*to enhance the EXEC procedure.              *)
USES Dos;
VAR
  WhatProg, Found : PathStr;

BEGIN
  Write('Enter the program name just as you');
  WriteLn(' would at the DOS prompt, with NO');
  Write('extension and NO path.  It can be a ');
  WriteLn('COM, EXE, or BAT file.');
  Write('Program name:');
  ReadLn(WhatProg);
  Found := FSearch(WhatProg+'.COM','');
  IF Found = '' THEN
    Found := FSearch(WhatProg+'.EXE','');
  IF Found = '' THEN
    Found := FSearch(WhatProg+'.BAT','');
  IF Found = '' THEN
    Found := FSearch(WhatProg+'.COM', GetEnv('PATH'));
  IF Found = '' THEN
    Found := FSearch(WhatProg+'.EXE', GetEnv('PATH'));
  IF Found = '' THEN
    Found := FSearch(WhatProg+'.BAT', GetEnv('PATH'));
  IF Found = '' THEN
    BEGIN
      WriteLn('Sorry, I cannot find "',WhatProg,'" anywhere!');
      Halt(1);
    END;
  Found := FExpand(Found);
  WriteLn('Press <Return> to execute ',Found);
  ReadLn;
  SwapVectors;
  IF Pos('.BAT',Found) > 0 THEN
    EXEC(GetEnv('COMSPEC'),'/C '+Found)
  ELSE
    EXEC(Found,'');
  SwapVectors;
  CASE DosError OF
    0 : WriteLn('Successful completion');
    1 : WriteLn('Invalid function');
    2 : WriteLn('File not found or path invalid.');
    5 : WriteLn('Access denied.');
    8 : WriteLn('Insufficient memory.');
  END;
END.
[ RETURN TO DIRECTORY ]