Command Prompt Emulator

This is a discussion on Command Prompt Emulator within the C++ Programming forums, part of the General Programming Boards category; Hey a couple weeks back I had an idea of making a program that emulates command prompt. So it will ...

  1. #1
    Emulator
    Join Date
    Feb 2008
    Posts
    43

    Talking Command Prompt Emulator

    Hey a couple weeks back I had an idea of making a program that emulates command prompt. So it will be like a stand alone command prompt. I made that except I do not know how to make it give more than 1 word. I tried strings but it won't work. I tried doing 2 chars but i dont know how to do that. I tried thinks like system(c + d), where c and d are both chars i get from the user. How would I do this?

    Here is a typical session:

    I type in 'net user'
    it gives the output of what i'd get when i would type just net by itself.

    I need help!
    Hand over your source code, and nobody gets hurt.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Use an input command that allows for spaces (i.e., a line-based command).

  3. #3
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    Negative, after the space you get the next char value. How would you put both char values into command prompt?
    Hand over your source code, and nobody gets hurt.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    post the code you have thus far.



    ITSA
    Socket Library!

  5. #5
    Emulator
    Join Date
    Feb 2008
    Posts
    43

    Talking

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
        string hi;
        while (1)
        {
        cout << ">";
        getline(cin, hi);
        system (hi); //ERROR ZONE
        
        }
        
        
        system ("PAUSE");
        return 0;
    }
    Error: cannot convert `std::string' to `const char*' for argument `1' to `int system(const char*)'
    Last edited by PЯO; 02-16-2008 at 06:29 PM. Reason: Showed error zone
    Hand over your source code, and nobody gets hurt.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    And what does system(hi.c_str()) do for you?

  7. #7
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    Quote Originally Posted by tabstop View Post
    And what does system(hi.c_str()) do for you?
    Nothing.
    Hand over your source code, and nobody gets hurt.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    maybe your program needs another while loop.



    ITSA
    Socket Library!

  9. #9
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    Tried. It doesn't. Why would it?
    Hand over your source code, and nobody gets hurt.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by PЯO View Post
    Nothing.
    Let me be more specific: what does putting system(hi.c_str()); in place of the line system(hi), saving your source file, and recompiling do for you?

    Hint: the answer is, "it fixes my problem."
    Last edited by tabstop; 02-16-2008 at 06:40 PM. Reason: got my . and _ mixed up

  11. #11
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    Quote Originally Posted by tabstop View Post
    Let me be more specific: what does putting system(hi.c_str()); in place of the line system(hi), saving your source file, and recompiling do for you?

    Hint: the answer is, "it fixes my problem."
    It doesn't work. I'm using Dev-C++ compiler.
    Hand over your source code, and nobody gets hurt.

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by PЯO View Post
    It doesn't work. I'm using Dev-C++ compiler.
    So am I. It does work, or at least this code does:
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
        string hi;
        while (1)
        {
        cout << ">";
        getline(cin, hi);
        system (hi.c_str()); //ERROR ZONE
    
        }
    
    
        system ("PAUSE");
        return 0;
    }
    Be sure to hit Ctrl-F11 to rebuild all. But it compiles clean and runs exactly like what you want. If you're getting compile errors, post them and we'll tell you what you've done wrong.

  13. #13
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    tabstop's right.
    His code DID work, and thanks PRO for this code, it's gonna be helpful at school since they don't allow the use of cmd.

  14. #14
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    Quote Originally Posted by HelpLol View Post
    tabstop's right.
    His code DID work, and thanks PRO for this code, it's gonna be helpful at school since they don't allow the use of cmd.
    Lol, that was the point
    Hand over your source code, and nobody gets hurt.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. x86 assembly emulator
    By maxorator in forum Tech Board
    Replies: 5
    Last Post: 12-01-2008, 07:21 AM
  2. Emulator Programming
    By Matt3000 in forum C Programming
    Replies: 2
    Last Post: 07-13-2006, 05:20 PM
  3. How do terminal emulator work?
    By Roaring_Tiger in forum C Programming
    Replies: 1
    Last Post: 04-15-2003, 08:20 PM
  4. Porting the NES emulator from DOS to Linux
    By billholm in forum Game Programming
    Replies: 14
    Last Post: 08-03-2002, 01:48 AM
  5. Writeing an emulator?
    By Eber Kain in forum Game Programming
    Replies: 5
    Last Post: 01-01-2002, 02:18 AM

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