Shell emulator

This is a discussion on Shell emulator within the C++ Programming forums, part of the General Programming Boards category; I have this shell emulator: Code: #include <iostream> #include <string> #include <windows.h> using namespace std; int main() { char path[500]; ...

  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
    dra
    dra is offline
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    never, EVER, use goto.

    use a loop instead.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,452
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21