Telegram Group & Telegram Channel
Note #31 go run и exit code

Вчера в твиттере увидел как Джонни Бурсиквот задает вопрос[1]: почему go run всегда возвращает exit code 1:
$ cat main.go
package main

import "os"

func main() {
os.Exit(199)
}
$ go run main.go
exit status 199
$ echo $?
1
А если собрать бинарник, а потом запустить то все будет ок:
go build main.go
./main
$ echo $?
199
Странно почему он не догадался сразу, go run - это 2 процесса и соответственно 2 exit кода, однако go run может вернуть только один exit код :)

Крутой коммент от Дэйва Чейни (перевод):
“Go run - это для игрушечных программ, серьезные программы нужно компилировать и запускать” :lol:

Вот часть исходника go run [3] “We ignore exit status.”:
// buildRunProgram is the action for running a binary that has already
// been compiled. We ignore exit status.
func buildRunProgram(b *work.Builder, a *work.Action) error {

}
Links:
[1] Твиттер thread https://twitter.com/jboursiquot/status/1177296876779057152
[2] Issue 2015 года на эту тему: https://github.com/golang/go/issues/13440
[3] https://github.com/golang/go/blob/master/src/cmd/go/internal/run/run.go#L146-L148



tg-me.com/golang_for_two/56
Create:
Last Update:

Note #31 go run и exit code

Вчера в твиттере увидел как Джонни Бурсиквот задает вопрос[1]: почему go run всегда возвращает exit code 1:

$ cat main.go
package main

import "os"

func main() {
os.Exit(199)
}
$ go run main.go
exit status 199
$ echo $?
1
А если собрать бинарник, а потом запустить то все будет ок:
go build main.go
./main
$ echo $?
199
Странно почему он не догадался сразу, go run - это 2 процесса и соответственно 2 exit кода, однако go run может вернуть только один exit код :)

Крутой коммент от Дэйва Чейни (перевод):
“Go run - это для игрушечных программ, серьезные программы нужно компилировать и запускать” :lol:

Вот часть исходника go run [3] “We ignore exit status.”:
// buildRunProgram is the action for running a binary that has already
// been compiled. We ignore exit status.
func buildRunProgram(b *work.Builder, a *work.Action) error {

}
Links:
[1] Твиттер thread https://twitter.com/jboursiquot/status/1177296876779057152
[2] Issue 2015 года на эту тему: https://github.com/golang/go/issues/13440
[3] https://github.com/golang/go/blob/master/src/cmd/go/internal/run/run.go#L146-L148

BY 🇺🇦 Go for two :)




Share with your friend now:
tg-me.com/golang_for_two/56

View MORE
Open in Telegram


🇺🇦 Go на двоих Telegram | DID YOU KNOW?

Date: |

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

That growth environment will include rising inflation and interest rates. Those upward shifts naturally accompany healthy growth periods as the demand for resources, products and services rise. Importantly, the Federal Reserve has laid out the rationale for not interfering with that natural growth transition.It's not exactly a fad, but there is a widespread willingness to pay up for a growth story. Classic fundamental analysis takes a back seat. Even negative earnings are ignored. In fact, positive earnings seem to be a limiting measure, producing the question, "Is that all you've got?" The preference is a vision of untold riches when the exciting story plays out as expected.

🇺🇦 Go на двоих from us


Telegram 🇺🇦 Go for two :)
FROM USA