kwgst@unix.cis.pitt.edu (Karol W Gieszczykiewicz) (12/05/90)
Greetings. I am a C programmer with a bit of 8088 assembly "fooling around". I am writing a program that has to load command.com (shell). It works, but I want it to display a little message that reminds the user of what they did. (just so they don't run my program again, instead of "exit"- ing back to it). I know it's possible because WordPerfect does it. Every time one presses <enter>, after exiting to shell, a short message appears, telling the user to type "exit" to return to WP. I want to know how to chain in such a message. I don't mind creating a modified copy of command.com and then running it. Anyone? Take care. I will summarize.
Unknown (12/05/90)
In article <67560@unix.cis.pitt.edu>, kwgst@unix.cis.pitt.edu (Karol W Gieszczykiewicz) says: > > > Greetings. I am a C programmer with a bit of 8088 assembly > "fooling around". I am writing a program that has to load > command.com (shell). It works, but I want it to display > a little message that reminds the user of what they did. > (just so they don't run my program again, instead of "exit"- > ing back to it). > > I know it's possible because WordPerfect does it. Every time > one presses <enter>, after exiting to shell, a short message > appears, telling the user to type "exit" to return to > WP. I want to know how to chain in such a message. I don't > mind creating a modified copy of command.com and then running > it. > > Anyone? > > Take care. I will summarize. You don't need to do that. Before loading command.com, ... putenv("prompt=\"Exit\" to return to <progname>$_%%prompt%%"); ... You may not need the formatting commands, this is just off the top of my head. If they are not needed, change \" to just " and %% to %. This should give you a prompt of: "Exit" to return to <progname> C:\> at every prompt. Carl Schelin tcs@mailer.jhuapl.edu
kdq@demott.com (Kevin D. Quitt) (12/06/90)
Did you try setting the prompt environment variable? -- _ Kevin D. Quitt demott!kdq kdq@demott.com DeMott Electronics Co. 14707 Keswick St. Van Nuys, CA 91405-1266 VOICE (818) 988-4975 FAX (818) 997-1190 MODEM (818) 997-4496 PEP last
sab@engr.uark.edu (Steven A. Breuer) (12/06/90)
In article <67560@unix.cis.pitt.edu>, kwgst@unix.cis.pitt.edu (Karol W Gieszczykiewicz) writes: > > I know it's possible because WordPerfect does it. Every time > one presses <enter>, after exiting to shell, a short message > appears, telling the user to type "exit" to return to > WP. I want to know how to chain in such a message. I don't > mind creating a modified copy of command.com and then running > it. > Look at the getenv() and putenv() functions. Most MS-DOS C compilers should have these functions. Use getenv() to get the prompt string. Then use putenv() to set the prompt to whatever you like. Now execute COMMAND.COM with the desired parameters. This only changes the prompt environment variable for your program - not its parent program. Steve Breuer sab@engr.uark.edu
paul@vaxeline.COM (Paul Selkirk) (12/06/90)
You could keep users from reloading your program in the following way: Set
an environment variable to indicate that you've spawned a DOS shell.
putenv("SHELL=yes");
In the initialization code for your program, test for the presence of this
variable, and abort with an message if it's found.
if (getenv("SHELL")) {
puts("Type EXIT to get back to FUTURE");
exit(1);
}
Since the variable is only in the environment of your program an programs
that it spawns (command.com), it goes away when you exit, so the user never
has to know about it.
Epsilon does it this way, and I heartily approve.
---------------------------------------------------------------------------
Paul Selkirk paul@ftp.com
FTP Software 26 Princess St., Wakefield, MA 01880
todd@ivucsb.sba.ca.us (Todd Day) (12/06/90)
kwgst@unix.cis.pitt.edu (Karol W Gieszczykiewicz) writes:
% I am writing a program that has to load
% command.com (shell). It works, but I want it to display
% a little message that reminds the user of what they did.
I suspect that you could modify the PROMPT string to include your
message...
--
Todd Day | todd@ivucsb.sba.ca.us | ucsbcsl!ivucsb!todd
* Ask me about the Gold Rush mini-rallye in August, 1991! *
darcy@druid.uucp (D'Arcy J.M. Cain) (12/06/90)
In article <67560@unix.cis.pitt.edu> Karol Gieszczykiewicz writes: > Greetings. I am a C programmer with a bit of 8088 assembly > "fooling around". I am writing a program that has to load > command.com (shell). It works, but I want it to display > a little message that reminds the user of what they did. > (just so they don't run my program again, instead of "exit"- > ing back to it). > > I know it's possible because WordPerfect does it. Every time > one presses <enter>, after exiting to shell, a short message > appears, telling the user to type "exit" to return to I don't believe you can make command.com do that but it would be simple to change the prompt. Try this: reminder db 'PROMPT=Type EXIT to return to FOOBAR', 0dh, 0ah old_prompt db MAX_PROMPT dup ? Now find the environment string for "PROMPT" and copy it to old_prompt. Create a new environment space (leave some room for child processes) and replace the PROMPT string with the above. Now when you EXEC just point to this new environment and VIOLA! instant annoying reminder. See the DOS Technical Reference Ch. 7 (DOS Control Blocks and Work Areas) for more information on the DOS Program Segment and the environment. One more point. If it is a problem to run your program twice, you should probably try to prevent this. A simple (but not perfect) solution is to create a lockfile somewhere when you run and check for it on startup. If it already exists then abort. If not then create it. Don't forget to erase it when finished running the program. In fact this may be a better solution than modifying the prompt. If the file exists simply explain that the program is already running and describe how to return to it at that point. E.g: C> foobar **NOTE** FOOBAR is already running. To return to it enter the command 'EXIT' C> If you use the lock file scheme it would be a good idea to add an erase command to your autoexec.bat for those power failures, tripped over plugs and three fingered salutes. -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | There's no government West Hill, Ontario, Canada | like no government! +1 416 281 6094 |
roy%cybrspc@cs.umn.edu (Roy M. Silvernail) (12/07/90)
kwgst@unix.cis.pitt.edu (Karol W Gieszczykiewicz) writes: > Greetings. I am a C programmer with a bit of 8088 assembly > "fooling around". I am writing a program that has to load > command.com (shell). It works, but I want it to display > a little message that reminds the user of what they did. > (just so they don't run my program again, instead of "exit"- > ing back to it). Should be very easy... The spawned command.com will inherit a copy of the parent's environment, so you can grab the current prompt and modify it, then spawn the new shell. Something like this (untested, but simple) char s[80]; sprintf(s,"Type EXIT to return\n%s",getenv("PROMPT")); putenv(s); This does not modify the master environment, so the prompt will revert to normal when your program exits. You'll want to take care to only make this call once, though, or else you'll end up with strange results on the second and later shells you spawn. -- Roy M. Silvernail |+| roy%cybrspc@cs.umn.edu |+| #define opinions ALL_MINE; main(){float x=1;x=x/50;printf("It's only $%.2f, but it's my $%.2f!\n",x,x);} "This is cyberspace." -- Peter da Silva :--: "...and I like it here!" -- me
reeves@dvinci (Malcolm Reeves) (12/09/90)
From article <67560@unix.cis.pitt.edu>, by kwgst@unix.cis.pitt.edu (Karol W Gieszczykiewicz): The simplest reminder for a shell is to change the DOS prompt. This is what wordperfect does and several other programs. You can "exec" the prompt command from your own program.
kwgst@unix.cis.pitt.edu (Karol Gieszczykiewicz) (12/15/90)
Greetings. A while back I asked how to remind the user that the program is still running and to just type "EXIT" to return to it. Well, I got a lot of responses. The general concensus is to: 1) Change the PROMPT variable 2) Set a varaiable SHELL=yes and then test it when entering (or reentering) 3) Create a temporary, locked file when exiting (bit dangerous :-) Since this is a summary, I will only post 1 example of each. Here's #1: From: NA Schellenberge <naschell@sunee.uwaterloo.ca> Subject: Re: Command.com and a message Have you considered changing the PROMPT environment variable? Something like this might do the trick (Turbo C source): #include <process.h> #include <stdio.h> #include <string.h> #include <stdlib.h> void shell_to_DOS(void) { char *command_com=getenv("COMSPEC"); char *old_prompt,*new_prompt,*tmp; tmp=getenv("PROMPT"); old_prompt=malloc(8+strlen(tmp)); if (old_prompt) { strcpy(old_prompt,"PROMPT="); strcat(old_prompt,tmp); } else { return; } new_prompt=malloc(strlen(tmp)+34); if (new_prompt) { strcpy(new_prompt,"PROMPT=Type EXIT to return...$_"); strcat(new_prompt,tmp); } else { return; } putenv(new_prompt); spawnl(P_WAIT,command_com,NULL); putenv(old_prompt); free(old_prompt); free(new_prompt); return; } The error handling needs improvement but I'm sure that you get the idea. (By the way, I didn't have time to test this so be forewarned...) #2 would consist of: (Beginning of program) a. get the variable SHELL using getenv() b. examine to see if it's equal to "yes" c. if it is, puts("Already running. Type EXIT to return"); d. else go on. * [your program goes here] * e. get the variable SHELL using getenv() f. store it in a temporary variable (something else might be using it - be on the safe side) g. putenv("SHELL=yes"); h. spawnl(P_WAIT,command_com,NULL); putenv(old_prompt); free(old_prompt); free(new_prompt); #3 would be only done if you really want to fundge things. One could write a small file, make it SYSTEM, HIDDEN, and READ ONLY and exit. Then, when restarting, you would have to see if it's still there. If so, exit with a message, else run. But what happens if the powerline goes down or you have to reboot? A typical Joe or Jane will never figure out why the program keeps crashing. Unless, you want to make a documented utility that removes such a file ;-) So: DON'T DO THIS. Thank you all for your help. Take care.
dahlstr@hus.chalmers.se (Gunnar Dahlstrom) (12/16/90)
In article <67560@unix.cis.pitt.edu>, kwgst@unix.cis.pitt.edu (Karol W Gieszczykiewicz) writes: |> |> Greetings. I am a C programmer with a bit of 8088 assembly |> "fooling around". I am writing a program that has to load |> command.com (shell). It works, but I want it to display |> a little message that reminds the user of what they did. |> (just so they don't run my program again, instead of "exit"- |> ing back to it). |> |> I know it's possible because WordPerfect does it. Every time |> one presses <enter>, after exiting to shell, a short message |> appears, telling the user to type "exit" to return to |> WP. I want to know how to chain in such a message. I don't |> mind creating a modified copy of command.com and then running |> it. |> |> Anyone? |> |> Take care. I will summarize. WordPerfect have a "nice" solution they change the prompt! So just change the environment variable prompt to look like this: set prompt=Type EXIT to return But you shold do this in your program i dont know wich language you are writing in, but in C it is simpel, use setenv funtion. =============================================================================== Gunnar Dahlstrom Chalmers University of Technology Div. Building Technology 412 96 Gothenbourg, Sveden E-Mail: dahlstr@hus.chalmers.se ===============================================================================