英文:
File does not exist error when I run hello.go program
问题
我正在遵循Go文档并尝试运行hello.go。
我使用msi安装程序在Windows 7上安装了go 1.1.2。
我有文件"C:\Go\pkg\tool\windows_386\8g.exe"(请参见下面的dir输出),但当我运行'go.exe run hello.go'时,我收到文件不存在的错误。
请帮忙。谢谢。
C:\>go.exe run hello.go
go build command-line-arguments: exec: "C:\Go\pkg\tool\windows_386g.exe":
文件不存在
C:\>go.exe version
go version go1.1.2 windows/386
C:\>go.exe run hello.go
go build command-line-arguments: exec: "C:\Go\pkg\tool\windows_386g.exe":
文件不存在
C:\>dir C:\Go\pkg\tool\windows_386g.exe
指定的路径无效。
C:\>dir C:\Go\pkg\tool\windows_386g.exe
C驱动器的卷是 Local Disk
卷的序列号是 C07E-54F5
C:\Go\pkg\tool\windows_386 目录
08/13/2013 07:04 AM 1,831,416 8g.exe
1 个文件 1,831,416 字节
0 个目录 11,407,892,480 字节可用
英文:
I am following go documentation and try to run hello.go.
I am on Windows 7 and install go 1.1.2 using msi installer.
I have file "C:\Go\pkg\tool\windows_386\8g.exe" (see dir output below), but when I do 'go.exe run hello.go', I get the file does not exist error.
Please help. Thank you.
C:\>go.exe run hello.go
go build command-line-arguments: exec: "C:\\Go\\pkg\\tool\\windows_386\g.exe":
file does not exist
C:\>go.exe version
go version go1.1.2 windows/386
C:\>go.exe run hello.go
go build command-line-arguments: exec: "C:\\Go\\pkg\\tool\\windows_386\g.exe":
file does not exist
C:\>dir C:\\Go\\pkg\\tool\\windows_386\g.exe
The specified path is invalid.
C:\>dir C:\Go\pkg\tool\\windows_386\g.exe
Volume in drive C is Local Disk
Volume Serial Number is C07E-54F5
Directory of C:\Go\pkg\tool\windows_386
08/13/2013 07:04 AM 1,831,416 8g.exe
1 File(s) 1,831,416 bytes
0 Dir(s) 11,407,892,480 bytes free
答案1
得分: 3
从[问题6224][1]中可以看出,如果在运行go.exe
之前将环境变量PATHEXT
设置为只有一个扩展名,就会出现这个错误。
set PATHEXT=.BAT
go run hello.go
> 期望的输出是什么?
没有错误,hello world程序正常运行。
> 实际看到的是什么?
go build command-line-arguments:
exec: "c:\Go\pkg\tool\windows_386\8g.exe": 文件不存在
8g
Windows 7 64位
go版本 go1.1.2 windows/386
在我的电脑上(W7 64位),我有:
set pa
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
一切都正常运行。
> LookPath
被调用时使用的是"c:\Go\pkg\tool\windows_386\8g.exe
",而PATHEXT
被以一种不好的方式设置,可以说是让LookPath
失败了。
[1]: https://code.google.com/p/go/issues/detail?id=6224
英文:
From [issue 6224][1], this error happens if you had the environment variable PATHEXT
set to only one extension, before running go.exe
.
set PATHEXT=.BAT
go run hello.go
> What is the expected output?
no errors and hello world program runs
> What do you see instead?
go build command-line-arguments:
exec: "c:\\Go\\pkg\\tool\\windows_386\g.exe": file does not exist
8g
Windows 7 64bit
go version go1.1.2 windows/386
On my computer (W7 64 bits), I have:
set pa
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
and everything runs just fine.
> LookPath
is called with "c:\Go\pkg\tool\windows_386\8g.exe
" and the fact that PATHEXT
is being set in an evil way let's say, make LookPath
fails
[1]: https://code.google.com/p/go/issues/detail?id=6224
答案2
得分: 1
对于Windows用户:
如果使用VSCode,请在终端中输入以下命令:
$env:GOOS="windows"
否则,请在Windows PowerShell中输入以下命令:
英文:
For windows users :
If using vscode type this on terminal
> $env:GOOS="windows"
else type this in windows powershell
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论