Skip to content

cmd/go: go run should mimic the running script #17813

@natefinch

Description

@natefinch

IMO, go run should always mimic the output of the program it is running, unless there is some problem generating that program. Currently, go run only ever returns exit code 0 on success, or 1 on failure, regardless of what error code the program exited with. I think it should return the same exit code as the program always. In addition, if the program exits with a non-zero exit code, go run prints "exit status 1" (or whatever the exit code was). Unless go run has a problem generating the program (can't find a file, can't compile, etc), then I don't think it should print anything out. Notably, if go run returned the right return code, that extra text would be extraneous anyway.

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.7

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

go run script.go
echo $?

where script.go is

package main
import "os"
func main() {
	os.Stderr.Write([]byte("Hi!"))
	os.Exit(2)
}

What did you expect to see?

Hi!
2

What did you see instead?

Hi!
exit status 2
1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions