[comp.sys.ibm.pc] DOS shell from within application

vlcek@mit-caf.MIT.EDU (Jim Vlcek) (11/29/88)

I would like to incorporate into a program I am writing in MSC5.0
(currently in small model), the ability to ``pop out'' into a DOS
shell and then return to the application by issuing the DOS EXIT
command.

The MSC ``system'' function is useful only for executing single
commands, whereas I would like to have a new DOS shell available.  I
have been trying to use the MSC ``spawn??'' functions (eg, spawnlp,
etc.) and using the program name ``command.''  This does get me a DOS
shell, but when I return, my program has often been corrupted.  What
seems to be happening is that constant (read only) storage is getting
corrupted, and it is being corrupted with data from the DOS environment.

Things like:

  char *out_mesg;
  out_mesg = "Hello, world\n";

get corrupted, I suspect that this is due to such constant data being
located in a centralized place in memory.  On the other hand, declared
variables such as:

  char out_mesg[] = "Hello, world\n";

do just fine, regardless of whether they are auto or static variables.
It looks like DOS is corrupting my constant space with environment
data when it spawns the new command processor.

Does anyone know how I can avoid this, or a different method of
spawning a DOS shell that works?

Thanks,
-- 
Jim Vlcek
vlcek@caf.mit.edu
!{harvard,rutgers}!mit-eddie!mit-caf!vlcek

posert@bonnie.ics.uci.edu (Bob Posert) (11/30/88)

In article <1549@mit-caf.MIT.EDU> Jim Vlcek writes:
>I would like to incorporate into a program I am writing in MSC5.0
>(currently in small model), the ability to ``pop out'' into a DOS
>shell and then return to the application by issuing the DOS EXIT
>command.
> [...]
>Things like:
>
>  char *out_mesg;
>  out_mesg = "Hello, world\n";
>
>get corrupted, I suspect that this is due to such constant data being
>located in a centralized place in memory.

The following program seems to work using Turbo C 1.0 under PC-DOS 3.1:
=======
#include <stdio.h>
#include <process.h>
#include <stdlib.h>
 
main(){
   char *const_str;
   char *command;
 
   const_str = "This is a constant string\n";
   command   = getenv("COMSPEC");
   printf("\n\nType Exit to leave subshell\n");
   spawnl(P_WAIT, command, command, NULL);
   printf("%s", const_str);
}
=======
You may want to add some error checking :-).
--Bob
--
Bob Posert
I'm: posert@bonnie.ics.uci.edu or {sdcsvax|ucbvax}!ucivax!bonnie!posert