Thread: changing the prompt???

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    10

    Lightbulb changing the prompt???

    hi! is it possible to change the command prompt to a $??
    i have to emulate the unix shell and kernel which will run under dos and i have to show the time, date etc and change the command prompt to a $ sign. how is that done? can someone please start me off in the right direction?
    thanks to anyone that answers.
    Jim

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    In dos...type;

    PROMPT $D $$

    This gives the time and the '$' sign


    LOL.....it the old days you must of changed your prompt as we all change our wallpaper and screensavers today

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    10
    thanks......but i have to write that in c.
    what is the code for the $ sign in c???
    thats what i need.
    thanks
    Jim

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > what is the code for the $ sign in c???

    Um... the $ sign is the $ sign in C. Now, are you talking about changing the system prompt, or the prompt your program uses to request input? If the latter, you can use whatever you feel like:

    printf("Enter something $ ");
    ...read input here...

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    I tried system(PROMPT $D $$), but it did not hold when my prog terminated.

    Is your project to create a mock shell that passes what you type to the command line?

    You could try this I suppose;

    Code:
    int main(void){
    	char typed[255] = {0};
    	cout << "$" ;
    	while(1){
    		cin.getline(typed,255);
    		if(!strcmp("exit",typed)) break;
    		system(typed);
    		cout << "$" ;
    	}
    	return 0;
    }
    Its pretty lame I admit , but commands like "DIR", "CD", "EDIT" and "DEL" work........

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > but it did not hold when my prog terminated.

    It won't hold when your program exits. Additionally, it won't hold when you open a dos window in Win9x, close it, and open a new one.

    You'll likely have to edit the autoexec.bat and replace it that way.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    You might wanna try:

    system("set prompt $D $$");

    This will set the system environment variable, and should stick around after your program closes (SHOULD, as I am not 100% sure about this.)

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>system("set prompt $D $$");

    I dont think that prompt is an environment vairable.......and so set doesnt work.......well I tried it on Win98 console and it choked

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    10
    yes! i need to change the command prompt through out the program. i can use printf("$"); but that only changes it once. how can i keep the $ sign until the program ends?

    the whole point of this is that i need to simulate the unix shell and kernel. the program should be able to do the following:

    date - will display the date
    time - will display the time
    ls - display and list the contents of a directory
    etc,

    is this quite difficult to achieve?
    any thoughts or ideas will be greatly appreciated! : )


    jim

  10. #10
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    If it's your program that's is to simulate a unix shell then you shouldn't be trying to alter the DOS prompt. It's your program so you can give it any prompt you like. Then you'd translate the unix comands entered into stdin and call the appropriate dos commands to output to stdout.

  11. #11
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Look at the code I posted above that simulates a poor command shell.......(Its in C++, but I got confused about what board I was on )

    Now to get he time....there are a few ways and funcs......but this is a start...

    Code:
    struct tm *thetime;
    time_t mytime;
    
    time( &mytime ); //system time count
    thetime = localtime( &mytime ); //convert it to local time 
    printf("%s",asctime(thetime)); //convert into a nice string and print
    To use it you need the <time.h>

    Now for custom unix commands.....well....
    Code:
    if(!strcmp("ls",typed)) {system("dir");}
    else if(!strcmp("whatever *nix command",typed)) {system("whatever it is in dos");}
    Well its a few ideas anyway

  12. #12
    Registered User
    Join Date
    Jan 2002
    Posts
    10
    thanks Fordy, i'll try that tomorrow.
    now be for i go to bed........about this $ sign for the command prompt. Sorensen said that because it is my program i can give it any prompt i like.......BUT how do i do that?????
    it is really puzzling me...
    well, time to go count some sheep
    jim

  13. #13
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    In the code above, substitute cout << "$"; for printf("$");

  14. #14
    Registered User
    Join Date
    Jan 2002
    Posts
    10
    thanks for all the help so far guys! : )

    can i just ask a question about the commands i have to use.
    a user has to type in a command (remember this program simulates a unix system) such as 'ls' which is to display and list the contents of a directory. should i have an array of stored commands such as:

    char commands [4] [4];

    strcpy (commands[0], "date");
    strcpy (commands[1], "ls");
    etc

    then compare the word from the user to the ones in the array?
    would that work. im getting confused!

    i'll carry on trying to work it out. if anybody wants to pass on any advice i'll be only too happy to listen!
    jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. changing the size of the command prompt in c++
    By diegozuke in forum C++ Programming
    Replies: 4
    Last Post: 03-11-2006, 05:32 PM
  2. Changing this to user prompt help.
    By Infuriate in forum C Programming
    Replies: 5
    Last Post: 12-04-2005, 05:01 PM
  3. Changing windows without changing?
    By Lionmane in forum Windows Programming
    Replies: 7
    Last Post: 10-19-2005, 11:41 AM
  4. Removing spaces from a "string"
    By sytaylor in forum C++ Programming
    Replies: 20
    Last Post: 03-25-2004, 10:14 AM
  5. Password prompt in unix w/o \b
    By rafe in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 08:54 AM