| Author |
Alternative to system("pause");?
|
|
| jbieger@gmail.com 2006-06-27, 1:20 am |
| Is there a UNIX alternative to using system("pause");, which pauses a
program on Windows computers while prompting "Press any key to
continue..." or something like that?
| |
| Pascal Bourguignon 2006-06-27, 1:20 am |
| jbieger@gmail.com writes:
> Is there a UNIX alternative to using system("pause");, which pauses a
> program on Windows computers while prompting "Press any key to
> continue..." or something like that?
sudo cat >/usr/bin/pause <<EOF
#!/bin/bash
read -p "Press the RETURN key to continue..."
EOF
sudo chmod 755 /usr/bin/pause
Of course, you could avoid forking a bash, calling this C function:
void pause(void){
printf("\nPress the RETURN key to continue...");
while('\n'!=getchar());
}
--
__Pascal Bourguignon__ http://www.informatimago.com/
PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
| |
| rrs.matrix@gmail.com 2006-06-27, 1:20 am |
|
jbieger@gmail.com wrote:
> Is there a UNIX alternative to using system("pause");, which pauses a
> program on Windows computers while prompting "Press any key to
> continue..." or something like that?
u can use the "read" command provided by the shell.
system("read -n 1");
this should do the job for u.
| |
| jbieger@gmail.com 2006-06-27, 7:27 am |
| OK, thanks guys!
rrs.matrix@gmail.com wrote:
> jbieger@gmail.com wrote:
>
> u can use the "read" command provided by the shell.
> system("read -n 1");
> this should do the job for u.
| |
| Rouben Rostamian 2006-07-03, 1:26 pm |
| In article <87veqn48zv.fsf@thalassa.informatimago.com>,
Pascal Bourguignon <pjb@informatimago.com> wrote:
>jbieger@gmail.com writes:
>
>...
>Of course, you could avoid forking a bash, calling this C function:
>
>void pause(void){
> printf("\nPress the RETURN key to continue...");
> while('\n'!=getchar());
>}
In a line-buffered stream there is no gurrantee that your prompt
will be printed, because it is not terminated by a newline.
You should change it to:
void pause(void){
printf("\nPress the RETURN key to continue...");
fflush(stdout);
while('\n'!=getchar());
}
|
|
|
|