Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Pause at the end of Command Line Scripts?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 28 August 2012 - 06:05 PM

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~

~Saint Squireen

Ad:

#2 Bacterius   Crossbones+   -  Reputation: 3518

Like
1Likes
Like

Posted 28 August 2012 - 07:19 PM

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*

You would get:

Copyright Windows blablabla

>> cd C:\some\path\to\my\program\
>> program.exe
Hello World
>>


Does it make sense?

"The best comment is a deleted comment."
website · blog

[maintenance in progress]


#3 Procstar   Members   -  Reputation: 103

Like
0Likes
Like

Posted 29 August 2012 - 11:49 AM

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;
}

#4 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 29 August 2012 - 03:51 PM

Thanks guys.

~Saint Squireen

#5 marek-knows.com   Members   -  Reputation: 121

Like
0Likes
Like

Posted 31 August 2012 - 06:13 PM

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
---
Free C++, OpenGL, and Game Development Video Tutorials @
www.marek-knows.com
Play my free games: Ghost Toast, Zing




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS