`go run: no go files listed` issue

14,698 views
Skip to first unread message

Joshua

unread,
Jun 13, 2013, 12:46:12 PM6/13/13
to golan...@googlegroups.com
According to the go run documentation: 
Run compiles and runs the main package comprising the named Go source files. If no files are named, it compiles and runs all non-test Go source files.

When I run just `go run`, I expect that it would compile all the files in the local directory and then run the binary. When I run this, I see this error: 
go run: no go files listed

Is this the expected behavior? NOTE: I am on Go 1.1.1 and Windows.

Joshua

Rob Pike

unread,
Jun 13, 2013, 1:24:07 PM6/13/13
to Joshua, golan...@googlegroups.com
That's a documentation bug in the 1.1 and 1.1.1 releases. The tip docs
say, correctly,

$ go help run
usage: go run [build flags] gofiles... [arguments...]

Run compiles and runs the main package comprising the named Go source files.
A Go source file is defined to be a file ending in a literal ".go" suffix.

James Bardin

unread,
Jun 13, 2013, 1:39:26 PM6/13/13
to golan...@googlegroups.com, Joshua

Is there anything stopping 'go run' from having semantics similar to 'go build', so that you could just type 'go run' as above, or 'go run pkgname'?

Matthew Kane

unread,
Jun 13, 2013, 1:41:57 PM6/13/13
to James Bardin, golang-nuts, Joshua
I use go run to run one go file in a directory full of go files, most of which are package main, so this would just fail in a different way. I have no idea how common this is.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
matt kane
twitter: the_real_mkb / nynexrepublic
http://hydrogenproject.com

Konstantin Kulikov

unread,
Jun 13, 2013, 3:14:17 PM6/13/13
to golan...@googlegroups.com
Confirming this issue on Fedora 18 with tip.
"go build" works fine, whether "go run" says no go files. "go run *.go" works fine, though.
i think it became this way somewhere around go1.1 release

Dominik Honnef

unread,
Jun 13, 2013, 4:42:12 PM6/13/13
to golan...@googlegroups.com
Konstantin Kulikov <k.kul...@gmail.com> writes:

> Confirming this issue on Fedora 18 with tip.
> "go build" works fine, whether "go run" says no go files. "go run *.go"
> works fine, though.
> i think it became this way somewhere around go1.1 release

go run never supported working with no specified files as far as I
remember.

For a reason why it doesn't you can take a look at the reasoning
presented in https://code.google.com/p/go/issues/detail?id=5511 – It
also documents the exact time at which the documentation was clarified.

cean...@gmail.com

unread,
Jul 16, 2013, 1:12:41 PM7/16/13
to golan...@googlegroups.com
I get the same error, only when my folders have a space in their names, I removed it and it works fine.

Dave Cheney

unread,
Jul 16, 2013, 5:32:03 PM7/16/13
to cean...@gmail.com, golan...@googlegroups.com
If this is the root cause, please log a bug. 


--

Jochen Voss

unread,
Aug 9, 2013, 7:03:57 AM8/9/13
to golan...@googlegroups.com, Joshua
Hi Rob,
So what is the recommended way to run a go program consisting of several
files?

I tried "go run *.go", but this doesn't work since it also picks up the *_test.go files
and then complains: go run: cannot run *_test.go files (...).
The following works:

    go run $(ls *.go | grep -v '_test\.go$')

but is awkward to type.

All the best,
Jochen
--

Rob Pike

unread,
Aug 9, 2013, 7:24:46 AM8/9/13
to Jochen Voss, golan...@googlegroups.com, Joshua
If you're running 'go run' in a directory with test files, you're doing it wrong.

go build && ./programname

-rob

Jochen Voss

unread,
Aug 9, 2013, 8:38:23 AM8/9/13
to golan...@googlegroups.com, Jochen Voss, Joshua
Hi Rob,


On Friday, 9 August 2013 12:24:46 UTC+1, Rob Pike wrote:
If you're running 'go run' in a directory with test files, you're doing it wrong.

Thanks, I wasn't aware of this.  Is it just because "go run" then becomes
awkward to use, or are there other problems?

In particular, I like the idea to make "go run" run the same set of files
as is compiled by "go build".  Would there be a problem with this approach,
or would this just need somebody to do the work of implementing this?

go build && ./programname

I'd like to keep my tests, so will probably go with this solution. 

Many thanks,
Jochen
--

Ian Lance Taylor

unread,
Aug 9, 2013, 9:00:07 AM8/9/13
to Jochen Voss, golang-nuts, Joshua
On Fri, Aug 9, 2013 at 5:38 AM, Jochen Voss <joche...@gmail.com> wrote:
> Hi Rob,
>
>
> On Friday, 9 August 2013 12:24:46 UTC+1, Rob Pike wrote:
>>
>> If you're running 'go run' in a directory with test files, you're doing it
>> wrong.
>
>
> Thanks, I wasn't aware of this. Is it just because "go run" then becomes
> awkward to use, or are there other problems?
>
> In particular, I like the idea to make "go run" run the same set of files
> as is compiled by "go build". Would there be a problem with this approach,
> or would this just need somebody to do the work of implementing this?

See the discussion at https://codereview.appspot.com/8119049 .

Ian

Pavulla LDA

unread,
May 8, 2022, 4:24:36 PM5/8/22
to golang-nuts
Hi,
I had the same issue!
Though I specified the file to pick as an argument and it worked!

go run ./filename.go


Regards,
Nkoi

Reply all
Reply to author
Forward
0 new messages