当我运行hello.go程序时,出现文件不存在的错误。

huangapple go评论88阅读模式
英文:

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设置为只有一个扩展名,就会出现这个错误。

  1. set PATHEXT=.BAT
  2. 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.

  1. set PATHEXT=.BAT
  2. 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

huangapple
  • 本文由 发表于 2013年8月23日 02:27:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/18388156.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定