Jump to content
  • Advertisement
Sign in to follow this  
Saint Squireen

Pause at the end of Command Line Scripts?

This topic is 2214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I pause at the end of my Command Line (Basic) Scripts (Programs)? All I want to do is, at the end of my running application, have it pause and wait until any key is pressed before exiting so that any final lines of text on the screen will stayand be legible.

~Saint Squireen~

Share this post


Link to post
Share on other sites
Advertisement
That's a fine way to do it. In fact, that's how it's usually done. Basically, use your language's idiom for reading a key from the standard input. That should be getchar(), getkey(), get(), read(), readln(), or something along those lines. Those will hang until the user inputs some stuff in, so you can precede it with some message such as "Press a key to exit". Or, if it's available, system("PAUSE") which will do the same thing (sorry, I don't do Basic so I wouldn't know the correct syntax).

Of course, if you want to avoid this, you can always run the script from the command-line itself (i.e. start the command-line interpreter, cd to your program and run it), this way the program will run "inside" the command-line interpreter and won't close the console once finished. It might be a bit harder to set up but it's generally the best way to do it, as waiting for user input to terminate the program isn't very script-friendly, especially for long-running scripts. You do have to deal with the CLI awkwardness but overall it works better except for throwaway programs (where just waiting for a keypress is faster to whip up and more convenient).

So instead of:

Hello World
*poof*
[/quote]
You would get:

Copyright Windows blablabla

>> cd C:\some\path\to\my\program\
>> program.exe
Hello World
>>
[/quote]

Does it make sense?

Share this post


Link to post
Share on other sites
In C++, the simplest way to pause a win32 console program is to make a call to the system such as:

#include <iostream>

using namespace std;

int main()
{
cout << "Hey, I'm paused!" << endl;

//program pauses an user is prompted to hit any key to continue
system ("pause");

return o;
}

Share this post


Link to post
Share on other sites
If you are using Visual Studio, run your code by pressing Ctrl+F5, rather than just F5. This will pause the console window when your program finishes rather than closing it

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!