Go system ("pause")

1,846 views
Skip to first unread message

ivan.h

unread,
Jun 10, 2010, 8:46:45 AM6/10/10
to golang-nuts
Go in there something like system ("pause") the C + + ?

Andrew Gerrand

unread,
Jun 10, 2010, 9:01:48 AM6/10/10
to ivan.h, golang-nuts
On 10 June 2010 14:46, ivan.h <ivan.h...@gmail.com> wrote:
> Go in there something like system ("pause") the C + + ?

The "pause" part of system("pause") is Windows-specific.

You could use the Run function from the exec package to the same effect.

If all you want to do is pause until the user presses enter, add 'os'
and 'bufio' to your import list and try:

bufio.NewReader(os.Stdin).ReadBytes('\n')

Andrew

ivan.h

unread,
Jun 10, 2010, 9:08:07 AM6/10/10
to golang-nuts
  bufio.NewReader(os.Stdin).ReadBytes('\n')

*Thanks*

mattn

unread,
Jun 10, 2010, 9:09:04 AM6/10/10
to golang-nuts
Do you mean pause in cmd.exe ?
That should call with following.

"cmd /c pause"

Thanks.

ivan.h

unread,
Jun 10, 2010, 10:07:27 AM6/10/10
to golang-nuts
too long to write this every time:
8g hello.go
8l -o hello.exe hello.8
created for this program .bat file to compile and run alone.
You only have to enter the file name.
This is the code - .bat file:

@echo off
color 2
title Go compiler
echo Go compiler
set /p name=Enter file name:
:start
cls
echo Go: %name%.go
start 8g %name%.go
start 8l -o %name%.exe %name%.8
IF NOT EXIST "%name%.8" DEL %name%.exe
IF NOT EXIST "%name%.8" msg * Compiled problem
IF EXIST "%name%.8" start %name%.exe

On 10 Юни, 16:09, mattn <mattn...@gmail.com> wrote:
> Смятате ли означава пауза в cmd.exe?Това трябва да се обадите на следните.
>
> "CMD / C пауза"
>
> Благодаря.
>
> На 10 юни, деветстотин четиресет и шеста година ч., "Ivan.h" <Ivan.hidz...@ gmail.com> написа:
>
>
>
> > Отидете там нещо като система ("пауза") на C + +?

Russ Cox

unread,
Jun 10, 2010, 3:34:02 PM6/10/10
to Andrew Gerrand, ivan.h, golang-nuts
> If all you want to do is pause until the user presses enter, add 'os'
> and 'bufio' to your import list and try:
>
>    bufio.NewReader(os.Stdin).ReadBytes('\n')

Note that this is only good once.
If stdin is not a user typing at a terminal
it may buffer more bytes past the \n it
is looking for. And then because the
reader is discarded after this line, the
bytes are gone.

Russ

ptolomy23

unread,
Jun 10, 2010, 3:56:45 PM6/10/10
to r...@golang.org, Andrew Gerrand, ivan.h, golang-nuts
Perhaps it should be:

func Pause() os.Error {
buf := make([]byte, 1)
for {
c, e := os.Stdin.Read(buf)
if c != 1 {
return e
}
if buf[0] == '\n' {
break
}
}
return nil
Reply all
Reply to author
Forward
0 new messages