dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: DOS Program only shows up for a second

  1. #1
    Join Date
    Apr 2008
    Posts
    4

    DOS Program only shows up for a second

    Hi, I just came across this wonderful forum and have been having a major issue. I am a complete newbie to C++ and I cant find the answer to my question. Whenever I compile and run a program, it only shows for a second and then closes.

    I have Windows Vista and am using Bloodshed Dev-C++ 4.99

    I put it on a jumpdrive on an XP comp, and it still popped up quickly. I am going to try Visual C++ 2008 Express Edition, which I am installing now. Does anyone know how to fix this?

    Thank You
    Last edited by velocity8; April 17th, 2008 at 11:53 AM.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: DOS Program only shows up for a second

    Welcome to Codeguru.

    Your program can be designed to be only visible for a moment, or, maybe your program crashes, or, .......

    Without any code or hint of what you are doing, we can't help you. So, you need to give us more info on your project and what you are doing with it.

  3. #3
    Join Date
    Apr 2008
    Posts
    4

    Re: DOS Program only shows up for a second

    a simple hello world program, or any program...

    Im trying a hello world prog.

  4. #4
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: DOS Program only shows up for a second

    Since this is a "DOS program" (console application), if you are starting it by double-clicking on it in explorer, then the behavior you see is normal.

    Open a DOS (cmd) window and then change to the directory with your application and run it from the command prompt.

    Hope that helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  5. #5
    Join Date
    Apr 2008
    Posts
    4

    Re: DOS Program only shows up for a second

    Ohh.. Is that why there is no execute button in C++ 08 Express?

    Also how do i change the directory and load it from DOS?

    I used to be able to do it on Visual C++ 6.0 so I wondered if there was an error that I didnt see.

    Thank You

  6. #6
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: DOS Program only shows up for a second

    Open a DOS (cmd) window... Press Start, then run and in the window type cmd

    In the resulting DOS window, use the cd command to change directories. For example, if your DOS window comes up with
    Code:
    C:\Documents and Settings\yourname>
    you can type
    Code:
    cd \dir1\dir2
    to change to C:\dir1\dir2 (assume that's where your program is. Now your prompt will show
    Code:
    C:\dir1\dir1>
    Type the name of your program and press return.

    This is really basic DOS/cmd stuff.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: DOS Program only shows up for a second

    Even better, cd at least is syntax shared with Unix. (I keep getting dir mixed up with ls, though....)

    If you don't want to bother with that, put "system("PAUSE");" at the end of the program. Or simply tell Visual Studio to "Start without debugging", which (for some reason) seems to insert the pause automatically.

    The thing is, once the program exits, there's no reason for the console window to stick around. You want the window to remain, you have to keep it from exiting.

  8. #8
    Join Date
    Apr 1999
    Posts
    27,449

    Re: DOS Program only shows up for a second

    Quote Originally Posted by Lindley
    If you don't want to bother with that, put "system("PAUSE");" at the end of the program.
    More likely, the programmer (embarrassingly) doesn't know how to use the command-line, and then resort to all sorts of things to get the program output, including the "system(PAUSE)", trick.

    What winds up happening is the new programmer does not know anything about what an executable file is (or that one is created), and how to run their program without IDE's. It's equivalent (but IMO worse) to a Java programmer who doesn't know how to run their Java apps outside of Eclipse.

    So bottom line is that any programmer who doesn't know how to use simple command-line commands shouldn't be a programmer.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 17th, 2008 at 11:33 PM.

  9. #9
    Join Date
    Feb 2002
    Posts
    4,640

    Re: DOS Program only shows up for a second

    Quote Originally Posted by Paul McKenzie
    More likely, the programmer (embarrassingly) doesn't know how to use the command-line, and then resort to all sorts of things to get the program output, including the "system(PAUSE)", trick.

    What winds up happening is the new programmer does not know anything about what an executable file is (or that one is created), and how to run their program without IDE's. It's equivalent (but IMO worse) than a Java programmer who doesn't know how to run their Java apps outside of Eclipse.

    So bottom line is that any programmer who doesn't know how to use simple command-line commands shouldn't be a programmer.

    Regards,

    Paul McKenzie
    Heh. I've got a number of batch files that I run from the command line to launch GUI based apps in different environments! Basically, the opposite of running a command line app from Explorer!

    Viggy

  10. #10
    Join Date
    May 2007
    Posts
    811

    Re: DOS Program only shows up for a second

    And to run within VC++, put breakpoint on the last line of main function.

  11. #11
    Join Date
    Nov 2007
    Posts
    613

    Re: DOS Program only shows up for a second

    Right click the name of your executable in the explorer window, pick "Properties" from the context menu, in the property sheet go to the Program tab and uncheck the "Close On Exit" option.

  12. #12
    Join Date
    Apr 2008
    Posts
    4

    Re: DOS Program only shows up for a second

    I fixed it, lol. It was the silliest thing ever. You go to Start without Debugging and it launches. Thanks for your help, I tried the DOS thing and the Properties thing and they worked. Now I am just starting to program and I just bought this book from Amazon "C++ Primer 5th Edition" by Stephen Prata, was it a good buy over some other books for beginners? and why was it published a few months before the 4th edition by Lippman?

    The main reason I bought this one was bcz I tohught this one would be newer with the <iostream> and not the <iostream.h> It confuses me a great deal.

    Kenny A.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)