I have been learning GoLang for some time and recently started facing this strange issue while running exe built using go build
command.
I am using VS Code 1.55 on Windows 10 (Enterprise edition) computer.
I created few sample programs in GoLang and was able to run them from VS Code without any issues.
Following is one such simple program for performing bubble sort.
package main
import "fmt"
func main() {
arr := []int{6, 2, 1, 3, 7, 5, 4, 8}
n := len(arr)
input := make([]int, n)
_ = copy(input, arr)
fmt.Println(input)
performBubbleSort(input, true)
fmt.Println(input)
}
func performBubbleSort(arr []int, popTop bool) {
// Removed the soring logic just to rule it out.
// This is literally an empty function with no code in it...
}
I normally run following commands to build and run a GoLang program.
go build
.\sampleapp.exe
This was running all fine with above commands. Recently I have been seeing following error while running .\sampleapp.exe
from VS Code terminal.
I tried to create fresh new GoLang programs and they also have the same issue. Sometimes just using fmt
causes this behavior or sometimes fmt
works fine but other modules such as os
causes the Access Denied
error.
Searched on Google about this and found that people are suspecting the Antivirus to block the exe from running and also suggested to run with Administrator privileges.
I am already running VS Code with Administrator privileges. Also I doubt that it is antivirus because I have other program created which is a web API developed in GoLang and I am able to run it without any issue.
I am scratching my head around this and searching in Google to find the cause and solution to this. I am not able to create any new GoLang program to experiment with other learnings due to this issue.
Any help would be appreciated on this. Feel free to ask if any other information is required on this.
EDIT 1:
Created a new fresh program as following.
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello world")
}
This programs has the same issue and shows the following output.
EDIT 2:
As per the suggestion from @MrFuppes I tried running command go run .\main.go
but that did not help.
When I tried to run go run .\main.go
for the above EDIT 1
code, it failed with Access denied error.
If I remove used of fmt
package, it works fine.
Also tried the same command for the program with performBubbleSort
above, and it ended up with the same error.