home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / exec.swg / 0006_DOS Shell.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-05-25  |  4.9 KB  |  129 lines

  1. {
  2.  ┌── GEORGE VAISEY ───────────────────────────────────────────────────┐
  3.  │ GV» I've read throught the book and even looked it up in the two   │
  4.  │ GV» pascal books I've got and can't seem to get any help.I'm       │
  5.  │ GV» trying (without luck) to get this this command:                │
  6.  │ GV» trying (without luck) to get this this PROMPT $mTYPE "EXIT" TO │
  7.  │ GV» RETURN to be sent as a command before it shells. This is so    │
  8.  │ GV» that the individual that shells out will always know that he   │
  9.  │ GV» needs to type EXIT to return.  If you can help or know of a    │
  10.  │ GV» better way PLEASE let me know.  Here is what I use to shell to │
  11.  │ GV» OS:                                                            │
  12.  │                                                                    │
  13.  │ GV» Begin                                                          │
  14.  │ GV»   ClrScr;                                                      │
  15.  │ GV»   TextColor(Yellow+Blink);                                     │
  16.  │ GV»   Writeln ('Type EXIT To Return To Program');                  │
  17.  │ GV»   SwapVectors;                                                 │
  18.  │ GV»   Exec(GetEnv('Comspec'), '');                                 │
  19.  │ GV»   SwapVectors;                                                 │
  20.  │ GV»   NormVideo;                                                   │
  21.  │ GV» End.                                                           │
  22.  │ GV» I want it to be                                                │
  23.  │ GV» TYPE "EXIT" TO RETURN                                          │
  24.  │ GV» then the prompt command.  Thanks again for your help.          │
  25.  │ GV»     George Vaisey                                              │
  26.  └────────────────────────────────────────────────────────────────────┘
  27.  
  28. George,
  29.  
  30.   You should get either Object Professional or Turbo Professional from
  31.   Turbo Power software (800) 333-4160 and use the xxDOS unit.  It has
  32.   routines in it to change environment variables on the fly.  These
  33.   routines work really well.
  34.  
  35.   In the mean time you can use the technique shown in the code below.
  36.   Beware however, that you MUST have enough environment space to deal
  37.   with the extra space required and that there will actually be two
  38.   copies of COMMAND.COM running in addition to the master copy.
  39.  
  40.   The technique shown in SHELLTODOS is not exactly what you asked for, but
  41.   it does show you how to do what you want.  SHELLTODOS1 is the code used
  42.   if you have either Object Pro or Turbo Pro.
  43.  
  44.   P.S.  Long lines of code may get truncated by my "QWK" mailer.  Inspect
  45.         the SHELLMESSAGE procedure as it appears it may get truncated.  Also
  46.         change all the WRITE commands in SHELLMESSAGE to WRITELN's.
  47.  
  48. [-------------------------------CUT HERE-----------------------------------]
  49. }
  50.  
  51. {$M 4096, 0, 655360 }
  52. Program DosShell;
  53. uses
  54.  OpDos,                                      { Needed only by SHELLTODOS1 }
  55.  Memory,
  56.  Dos,
  57.  CRT;
  58.  
  59.  
  60. Procedure ShellMessage ( ProgName : String );
  61.   Function Extend ( AStr : String; ML : byte ) : String;
  62.   begin
  63.     while ord ( AStr[0] ) < ML do
  64.       AStr := AStr + ' ';
  65.     Extend := AStr;
  66.   end;
  67. begin
  68.  clrscr;
  69.  Change the following 6 lines to WRITELN's then delete this line entirely.
  70.  write(' ╔═════════════════════════════════════════════════════════════════╗');
  71.  write(' ║ ■ While in the DOS SHELL, do not execute any TSR programs like  ║');
  72.  write(' ║   SideKick or DOS''s PRINT command.                              ║')
  73.  write(' ║ ■ Type EXIT and press ENTER to quit the SHELL and return to the ║');
  74.  write(Extend ( ' ║   ' + ProgName  + ' program.', 67 ), '║' );
  75.  write(' ╚═════════════════════════════════════════════════════════════════╝');
  76. end;
  77.  
  78.  
  79. Procedure ShellToDos ( ProgName : string );
  80. var
  81.  T : text;
  82.  D : string;
  83. begin
  84.  (* Save current directory                                    *)
  85.  GetDir ( 0, D );
  86.  
  87.  (* Create a DOS batch file with a PROMPT command             *)
  88.  assign  ( T, 'DOSSHELL.BAT' );
  89.  rewrite ( T );
  90.  writeln ( T, '@echo off' );
  91.  writeln ( T, 'Prompt [EXIT] $p$g' );
  92.  writeln ( T, GetEnv ( 'COMSPEC' ) );
  93.  close   ( T );
  94.  
  95.  (* Execute the batch file which in turn executes COMMAND.COM *)
  96.  ShellMessage ( ProgName );
  97.  DoneDosMem;
  98.  swapvectors;
  99.  exec ( GetEnv ( 'COMSPEC' ), '/c DOSSHELL.BAT' );
  100.  swapvectors;
  101.  InitDosMem;
  102.  
  103.  (* Erase the batch file and restore the working directory    *)
  104.  erase ( T );
  105.  chdir ( D );
  106. end;
  107.  
  108.  
  109. Procedure ShellToDos1 ( ProgName : string );
  110. var
  111.  NewPrompt : String;
  112.  D : string;
  113. begin
  114.  getdir ( 0, D );
  115.  ShellMessage ( ProgName );
  116.  NewPrompt := 'Type "EXIT" and press ENTER to return to DOSSHELL'^M^J+
  117.               '[' + ProgName + '] ' + GetEnvironmentString ('PROMPT');
  118.  ShellWithPrompt ( NewPrompt, NoExecDosProc );
  119.  chdir ( D );
  120. end;
  121.  
  122.  
  123. begin
  124.  InitMemory;
  125.  ShellToDos  ( 'DosShell' );
  126.  ShellToDos1 ( 'DosShell' );
  127.  DoneMemory;
  128. end.
  129.