🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.msdos.programmer
3 messages
3 total messages Started by JOHN M. TROIANO Thu, 07 Jan 1993 14:05
Re: question on spawning DOS from C prog
#7499
Author: JOHN M. TROIANO
Date: Thu, 07 Jan 1993 14:05
69 lines
2313 bytes
In article <tim.36.726368023@tim.src.utah.edu>, tim@tim.src.utah.edu (Tim Ma) wr
ites:
>>Subject: Re: question on spawning DOS from C prog
>>Date: 6 Jan 93 10:50:55 GMT
>>jmt7@ns1.cc.lehigh.edu (JOHN M. TROIANO) writes:
>>
>>>For example, after spawning DOS the user would
>>>see:
>>>            <Type EXIT to return to program>      <--this would appear
>>>                                                     each time <RET> hit
>>>            C:\
>>>    Is there, perhaps, a parameter to COMMAND.COM to do this?
>
>Reply was:
>------------------------------------------------------------------------
>>In your function declare something like:
>>
>>      static char prompt[]="PROMPT=<Type EXIT to return to program>$_$_$P";
>>
>>and before the spawnl() do a
>>
>>      putenv(prompt);
>>
>>to get exactly what you want.
>>
>>Greetings,
>>Wolfgang
>>--
>>siebeck@infoac.rmi.de (Wolfgang Siebeck)
>
>Is this possible?  It was my understanding that 'spawn' called a new command
>shell so any changes in the environment would not be carried over.
>
>I've always used 'spawnl' with the 'e' suffix to set or pass on environment
>variables.
>
>Curiously,
>
>Tim Ma
>Associate Programmer
>University of Utah
>Email:  tim@src.cppa.utah.edu
>

Hi, I am the original poster of this problem: this is especially to
Tim and Wolfgang. I tried the code below (which is I think what both
of you guys are suggesting) but it does'nt work (the new prompt
string is ignored). Any ideas?     - John.

#include <stdio.h>
#include <process.h>
#include <dos.h>
#include <stdlib.h>

int main( int argc, char *argv[], char **envp )
{

printf( "\ninside main, spawning DOS\n" );
sleep( 2 );

putenv( "prompt=$_type EXIT to return to program $_$_$p$g" );

spawnlpe( P_WAIT, "command.com", NULL, envp );

printf( "\nback from spawn!\n" );

sleep( 2 );

}
Re: question on spawning DOS from C prog
#7520
Author: Chris Fortier
Date: Fri, 08 Jan 1993 00:59
51 lines
2013 bytes

In article <1993Jan7.140524.15787@ns1.cc.lehigh.edu> jmt7@ns1.cc.lehigh.edu (JOHN M. TROIANO) writes:

[ STUFF DELETED ]

   Hi, I am the original poster of this problem: this is especially to
   Tim and Wolfgang. I tried the code below (which is I think what both
   of you guys are suggesting) but it does'nt work (the new prompt
   string is ignored). Any ideas?     - John.

   #include <stdio.h>
   #include <process.h>
   #include <dos.h>
   #include <stdlib.h>

   int main( int argc, char *argv[], char **envp )
   {

   printf( "\ninside main, spawning DOS\n" );
   sleep( 2 );

   putenv( "prompt=$_type EXIT to return to program $_$_$p$g" );

   spawnlpe( P_WAIT, "command.com", NULL, envp );

   printf( "\nback from spawn!\n" );

   sleep( 2 );

   }



Sigh.  Please RTFM.  The third parameter to spawn???() is argv[], a list of
parameters to the spawned executable.  This means that argv[0] must be the
name of the executable.  I know this seems redundant, but it does have a
purpose (changing path information, passing info to the child program, etc.).

Change the spawn???() command to the following, and the program should work:

	spawnlpe(P_WAIT, "command.com", "command.com", NULL, envp);
                                ^              ^              
                                |              |        
                               path         argv[0]     


Chris Fortier
Borland C++ Run Time Library QA

cfortier@borland.com
Re: question on spawning DOS from C prog
#7561
Author: Lee Hollingworth
Date: Sat, 09 Jan 1993 10:32
49 lines
1718 bytes
jmt7@ns1.cc.lehigh.edu (JOHN M. TROIANO) writes:

>In article <tim.36.726368023@tim.src.utah.edu>, tim@tim.src.utah.edu (Tim Ma) wr
>ites:

>Hi, I am the original poster of this problem: this is especially to
>Tim and Wolfgang. I tried the code below (which is I think what both
>of you guys are suggesting) but it does'nt work (the new prompt
>string is ignored). Any ideas?     - John.

I am neither Tim nor Wolfgang, but the following *does* work!

#include <process.h>
#include <stdlib.h>
#include <stdio.h>

int shell(char *);

void main(void)
{
   static char *message = "PROMPT=Type EXIT to return to program $_$P$G ";

   if (shell(message) == -1) {
      fprintf(stderr, "Error: cannot shell to DOS\n");
   }
}

/***
 * function: shell
 * purpose:  shell out to DOS operating system.
 * passed:   prompt -- prompt to be displayed in DOS environment.
 * returns:  -1 -- error occured
 *            ? -- the child process's exit status
 ***/
int shell(char *prompt)
{
   char *comspec = getenv("COMSPEC");

   if (!comspec) {
      return -1;
   }
   if (putenv(prompt)) {
      return -1;
   }
   return spawnl(P_WAIT, comspec, NULL);
}

Lee Hollingworth
s1110238@giaeb.cc.monash.edu.au
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads