简体   繁体   中英

Golang - windows console exits while running go.exe

I installed Go in Windows 10 with the MSI installer. However, when I run go in cmd (or PowerShell) with an argument, such as env, build, install, list, ... The console window closes (or crashes?) after the go command is run. This prevents me from seeing any errors or anything while compiling go code.

Is there some sort of log in windows which contains console host data, such as crashing, errors, and warnings? This would be very helpful to find out if console or console host is crashing for some reason.

As an example:

go env

won't output anything and the console window will immediately close.

Edit: Just to clarify, I am not running this command in the run dialog, I am running it from an administrator command prompt (I tried using PowerShell, also no luck). If I run:

go help

It will work properly. However, as soon as I run go with any other argument, such as:

go install <target>

or

go build <target>

The process will work but the console will exit before giving me any information.

Edit:

I've discovered a temporary fix... If I run go commands in a Cygwin terminal they work as usual. This is very strange.

Press win+r and in the resulting dialog type %COMSPEC% . This will start a new copy of the SPECified COMmand interperter, by default cmd.exe on most modern Windows versions.

Run your Go commands in this new window or others like it.

Your problem seems to be that you are trying to run the commands directly. Windows automatically creates a command prompt to run these commands in, but it closes as soon as the command is finished, before you can read the output.

I figured it out, I have Cygwin installed and I put it in my path environment variable. Turns out the git installation from Cygwin was interfering with the regular up to date, git installation. This was causing go with args to only work if I had the Cygwin terminal running. On golang-nuts someone also mentioned that some git versions have some bug where come.exe is called causing go commands to fail on windows.

To fix I just removed Cygwin from path and updated git to latest version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM