-1

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.

Patrick
  • 375
  • 3
  • 12
  • 2
    How precisely are you running that command? – JimB Sep 24 '17 at 18:19
  • I hate to suggest something so basic, but have you tried restarting Windows? I feel like it shouldn’t be necessary, but... it is Windows, after all ;) – Jonathan Sep 24 '17 at 18:56
  • 1
    It seems like something is killing conhost.exe (the console host process), or it's crashing. Try using the legacy console instead. In the console properties on the options tab, select the option to use the legacy console. Close it and try running a Go command in a new command prompt. – Eryk Sun Sep 25 '17 at 00:50
  • @eryksun I tried legacy console also tried running as administrator and compatibility on go.exe. It's still not working properly. – Patrick Nov 14 '17 at 01:35

2 Answers2

2

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.

Milo Christiansen
  • 3,204
  • 2
  • 23
  • 36
  • Thanks for the help, however, the console window is still closing before I can read anything, the build command works but gives me no information if there is a compiler error. This never happened on any system I've previously used. – Patrick Sep 24 '17 at 20:44
  • Wait. The command prompt you *manually opened* closes when the command finishes? That is impossible, you can't even do that if you want to. (Well, you probably could if you *really* wanted to, but it would be a horrid hack) – Milo Christiansen Sep 24 '17 at 22:47
  • @Patrick What is the output of `go build -x -v os 1> out.txt 2>&1`? Eg, what does `out.txt contain? – Milo Christiansen Sep 24 '17 at 23:06
  • Yes that is exactly what is happening, the command window I manually opened closes when the command finishes, the out.txt file contains: WORK=C:\Users\\*MY USERNAME*\AppData\Local\Temp\go-build872561830 – Patrick Sep 24 '17 at 23:12
  • Sadly, that output is *exactly* what it is suposed to be, no error messages or anything. This is a very strange issue... Did the command prompt close after running the given comand as well? – Milo Christiansen Sep 24 '17 at 23:18
  • yup it closed but still generates the file, I don't see any text pop up before it closes either. – Patrick Sep 24 '17 at 23:20
  • Displaying no text is normal in this case (since output is redirected to the file), closing the window is very much *not* normal however. Hmm... Let me think for a bit. – Milo Christiansen Sep 24 '17 at 23:23
  • Try `go build -x -v os 1> out.txt 2>&1 && echo "This sure is weird..." 1>> out.txt 2>&1` If that produces the expected ouput (same as last time, but with the extra echoed line after it) then you can paste that same command into a new text file, rename to `test.bat`, and replace the `&&` with a newline. Run `test` and report results. If that fails in the same way then... Well I don't know what to tell you. – Milo Christiansen Sep 24 '17 at 23:33
  • Just to be clear, I am trying to figure out *when* exactly the window decides to close. This will help tell if it is a weird Windows issue or a Go problem. – Milo Christiansen Sep 24 '17 at 23:34
  • the output is: WORK=C:\Users\\*MY USERNAME*\AppData\Local\Temp\go-build967449950 "This sure is weird..." with a newline after this sure is weird – Patrick Sep 24 '17 at 23:57
  • Do you think the installation could be at fault, maybe I should install Golang from source if possible – Patrick Sep 24 '17 at 23:59
  • OK, that is the expected output again, but it obviously isn't quiting the command prompt until the Go command is finished. This is so weird it is beyond words, I no longer have any idea what the problem could be... You can try uninstalling Go, making sure to clear out any changes to your environment, and install manually from the archive distrabution, restarting your computer after uninstalling, and after reinstalling, *maybe* that will help... – Milo Christiansen Sep 25 '17 at 00:05
  • Oh boy... That's exactly what I did before resorting to asking a question on SO, do you think I should file a bug report or something? – Patrick Sep 25 '17 at 00:22
  • 1
    Ask on the Go Nuts mailing list first, you are more likely to get a true expert that way. – Milo Christiansen Sep 25 '17 at 00:36
0

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.

Patrick
  • 375
  • 3
  • 12