Original post

Hi ,
What is diferent go run main.go | go run .
When i use “go run .” , what i run ? :smiley: ( sorry for bad eng )
( maybe this image can , help understand you )

Thanks :slight_smile:

Did you tried to read the manual (https://golang.org/cmd/go/#hdr-Compile_and_run_Go_program)?

Compile and run Go program

Usage:

go run [build flags] [-exec xprog] package [arguments…]

Run compiles and runs the named main Go package. Typically the package is specified as a list of .go source files from a single directory, but it may also be an import path, file system path, or pattern matching a single known package, as in ‘go run .’ or ‘go run my/cmd’.

By default, ‘go run’ runs the compiled binary directly: ‘a.out arguments…’. If the -exec flag is given, ‘go run’ invokes the binary using xprog:

‘xprog a.out arguments…’.

If the -exec flag is not given, GOOS or GOARCH is different from the system default, and a program named go_$GOOS_$GOARCH_exec can be found on the current search path, ‘go run’ invokes the binary using that program, for example ‘go_js_wasm_exec a.out arguments…’. This allows execution of cross-compiled programs when a simulator or other execution method is available.

The exit status of Run is not the exit status of the compiled binary.

Hi, @raifpy,

When you run go run ., the go program looks in the current directory (that’s what “.” means) for a main package and a main function in one of the files in that package.

When you run go run main.go, instead of checking the directory with a file that has a main function, the go program looks in the main.go file for that function and executes it just like go run .. The only difference I know of is that if you change the filename (e.g. from main.go to mypackage.go or something), then go run main.go will obviously stop working but go run . will keep working.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.