Thread: Shell emulator

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    12

    Shell emulator

    I have this shell emulator:

    Code:
    #include <iostream>
    #include <string>
    #include <windows.h>
    using namespace std;
    int main()
    {
    char path[500];
    GetCurrentDirectory(500,path);
    std::string command;
    start:
    cout << path << ">";
    getline( cin, command );
    system(command.c_str());
    goto start;
    }
    How do I make it so that you can use the cd function to change the directory? Right now it doesn't work.

  2. #2
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    never, EVER, use goto.

    use a loop instead.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    How do I make it so that you can use the cd function to change the directory? Right now it doesn't work.
    parse command before passing it to system
    if you encounter cd - extract path
    update path var (which should be MAX_PATH long)
    and change the current dir of your program
    do not call system in this case
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 05-27-2009, 12:26 PM
  2. What shell is more powerful?
    By xddxogm3 in forum Tech Board
    Replies: 10
    Last Post: 07-24-2004, 10:47 PM
  3. System.ini Shell Problems
    By (TNT) in forum Windows Programming
    Replies: 2
    Last Post: 08-26-2001, 01:05 PM