DOS question

Status
Not open for further replies.
Greetings to you all. This is my first time to post, but I have been reading for a long while. Now I must come to you for help. I am learning c++ right now. I have a couple of books and i am eating this info up! I seem to have a problem that when i compile my source code, the exe it generates is doing something wierd. Well, I think its the OS, but im not sure. I click on the exe and the dos window pops up and then dissapears real fast. I was running win xp pro and thought maybe this is the no dos thing in winxp. So I tried it in 2000. No luck....I even tried it with some simple hello world code. The dos window doesnt stay up so that i can enjoy seeing my program.
 
Try writing a little batch file like this.

Open notepad, and paste the following script.


@echo off
%1 %2 %3 %4 %5 %6 %7 %8 %9
Pause


Save it in your windows directory as 'run.bat'

now, try running the program from the run box on the start menu,

eg, for a program in the windows directory called xyz.exe

at the run box type 'run xyz.exe' and hit enter.

The batch file 'run.bat' will hold the window open displaying the result oif running 'xyz.exe' untill you press a key.

Hope this helps
 
yes thank you for the fix......i had already done this....but i would rather know how to fix it....is windows supposed to do this casue i have before gotten this to work....thnks though
 
or you can try executing the exe from a dos prompt - that may display the info you want (maybe)
 
nope....neither one worked....thnks for tryin....i tried running it in compatibility mode...and that didnt work either......
 
If you want the CLI window to remain you can do one of the following:

1) Run command prompt, navigate to your program's directory and run your exe from the command line.

2) Right click on your .exe file, choose properties. Under "Program" untick "Close on exit" box.

3) At the end of your program, add a statement that waits for user input like "getch()".

4) Make a batch file like shown above
 
all of the previous posts are correct. it's not a problem with anything. that's just how it works.

if you have tried it from a command prompt ("cmd.exe" from the start->run box) and it still closes then you've got something funky going on, probably an access violation or something but i doubt you're causing one of those in "Hello world", but maybe you are, i've seen some people do some weird things.

anyways if that's not a viable solution *ie, if you dont always want to use the command prompt to run the program* you can use method 3 that nodsu suggested above.

i used to always use...

#include<conio.h>
...
int main(){
...
while(!kbhit());
return 0;
}

which has basically the same effect as nodsu's #3.
 
Status
Not open for further replies.
Back