Golang Web program starts automatically and hides the cmd window

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Note: The method designed in this article, although the ability to hide the console window, but not the true meaning of "background run", at this time, if you log off the server, then all the running Golang Web service program will be terminated, the workaround:

Click using. NET to solve the problem of Go Web service stop after server logoff


If a server has 10 Golang Web, each of which displays a CMD window, it will be difficult to see, resolved as follows:

1) Go build your web to generate an EXE file

For example, my project is called "MyWeb", then I need to open cmd on the root of my project and execute a command: Go build myweb. A Myweb.exe file is generated


2) Make BAT file to launch the EXE file through the bat file:

Create a new empty bat file, add the absolute path of the myweb.exe generated in the previous step to the bat file, and then double-click the bat file to start the Myweb.exe file.

At this point, there will be a cmd window pops up, it is very bad to see, if we want to let Myweb.exe background to run, just need to add the following code at the top of the bat file:

@echo offif "%1" = = "h" goto Beginmshta vbscript:createobject ("Wscript.Shell"). Run ("" "%~nx0" "H", 0) (window.close) & &exit:beginrem

At this point, the full code for the bat file is as follows:

@echo offif "%1" = = "h" goto Beginmshta vbscript:createobject ("Wscript.Shell"). Run ("" "%~nx0" "H", 0) (window.close) & &exit:beginremc:\gopath\src\myweb\myweb.exe

3) automatically run BAT file on boot:

Method 1: Modify the Registry method:

Start-run-enter "regedit" (not including quotation marks)-Find the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run item, right-click on its right window, Select the new string value, double-click the new string value, enter the program path you want to start in the value data, and note that the entire path is quoted, which is: "C:\GOPATH\src\myweb\myweb.exe"

Method 2:.vbs Script Start method
At this point we need to build a. vbs script that executes the scripts in the background, with the following script:

then save the file as Script.vbs and put it in "Start-All Programs-and start-up".






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.