home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol8n01.zip / EXECDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1988-10-06  |  1KB  |  50 lines

  1. {$M 1024,0,0}
  2. PROGRAM Exec_Demo;
  3. (*By Neil J. Rubenking*)
  4. (*Demonstrates the use of new TP 5.0 routines *)
  5. (*to enhance the EXEC procedure.              *)
  6. USES Dos;
  7. VAR
  8.   WhatProg, Found : PathStr;
  9.  
  10. BEGIN
  11.   Write('Enter the program name just as you');
  12.   WriteLn(' would at the DOS prompt, with NO');
  13.   Write('extension and NO path.  It can be a ');
  14.   WriteLn('COM, EXE, or BAT file.');
  15.   Write('Program name:');
  16.   ReadLn(WhatProg);
  17.   Found := FSearch(WhatProg+'.COM','');
  18.   IF Found = '' THEN
  19.     Found := FSearch(WhatProg+'.EXE','');
  20.   IF Found = '' THEN
  21.     Found := FSearch(WhatProg+'.BAT','');
  22.   IF Found = '' THEN
  23.     Found := FSearch(WhatProg+'.COM', GetEnv('PATH'));
  24.   IF Found = '' THEN
  25.     Found := FSearch(WhatProg+'.EXE', GetEnv('PATH'));
  26.   IF Found = '' THEN
  27.     Found := FSearch(WhatProg+'.BAT', GetEnv('PATH'));
  28.   IF Found = '' THEN
  29.     BEGIN
  30.       WriteLn('Sorry, I cannot find "',WhatProg,'" anywhere!');
  31.       Halt(1);
  32.     END;
  33.   Found := FExpand(Found);
  34.   WriteLn('Press <Return> to execute ',Found);
  35.   ReadLn;
  36.   SwapVectors;
  37.   IF Pos('.BAT',Found) > 0 THEN
  38.     EXEC(GetEnv('COMSPEC'),'/C '+Found)
  39.   ELSE
  40.     EXEC(Found,'');
  41.   SwapVectors;
  42.   CASE DosError OF
  43.     0 : WriteLn('Successful completion');
  44.     1 : WriteLn('Invalid function');
  45.     2 : WriteLn('File not found or path invalid.');
  46.     5 : WriteLn('Access denied.');
  47.     8 : WriteLn('Insufficient memory.');
  48.   END;
  49. END.
  50.