#1
  1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95

    console app question


    damn i feel like a dumbass, i havent made a console app in probably 4 or 5 months, and i forgot the reason why when i run a console app directly from the .exe outside of MSVC++, it closes automatically.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    I think a lot of people use an input prompt to keep the screen from disappearing:

    getch();
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    19
    Rep Power
    0
    i use the system("pause") from the windows.h header file to pause it till a key is pressed
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Stupid question: How are you running it?

    Normal way:
    1. Open a DOS window (usually the first thing I open up after booting.
    2. cd to the EXE's directory (assuming that that directory is not in the PATH -- eg, all my utilities are in C:\UTIL which is in the search path, so I can run them from anywhere).
    3. Run the program from the command line.

    For the life of me, I cannot understand how running the program could cause the DOS window to close.

    Now, we have encountered that problem when we would invoke a DOS command from within a Windows app; eg, adding grep to the Tools menu in VC++1.52. In that case, we had to wrapper grep within a batch file that paused after running grep, or else the window would close on us immediately. GREP.BAT looks like this:
    Code:
    c:\util\grep.exe -n %1 %2 | more
    pause

    EDITED 2003 May 02, 1635 PDT:
    Honest, guys, I'm not trying to be a curmudgeonous old DOS'r (if for no other reason than I don't need to try), but it would just never occur to me to run a console app any way other than from DOS. Yes, I'll launch Windows apps through Windows Explorer or Run, but never a console app.

    ------------------------------------------------
    DOS? Was ist DOS?
    Last edited by dwise1_aol; May 2nd, 2003 at 06:44 PM.
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    >> Stupid question: How are you running it?
    I'm guessing that he's navigating to the directory in Windoze explorer and double clicking on the exe.

    Alternatively, he could also be using using Start-->Run

    Either way, after the program is done, it will return control back to the program that spawned it, (i.e.) Windows Explorer. Windows will then close the console window, since the program is no longer running.

    If you open a DOS window and follow dwise_aol's instructions, then when the program is done, it returns control back to the program that spawned it (i.e.) the DOS window. That's why your DOS window will still stay open on the screen
  10. #6
  11. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    yea i was running it from explorer. if i run it from dos prompt it's not a problem, it just returns control back to dos. i got it fixed now, thanks.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    "...i forgot the reason why when i run a console app directly from the .exe outside of MSVC++, it closes automatically."

    Ahhh...the "why" is what you were after. Sorry.
  14. #8
  15. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    Originally posted by 7stud
    "...i forgot the reason why when i run a console app directly from the .exe outside of MSVC++, it closes automatically."

    Ahhh...the "why" is what you were after. Sorry.
    -nope u were right! i was looking for both actually, the why and the how to fix this. i ended up scrounging some old code from last year's class, and i found that i used, guess what: cin.get() ! :)

IMN logo majestic logo threadwatch logo seochat tools logo