This is a creation in Article, where the information may have evolved or changed.
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:
[Plain]View Plaincopyprint?
- @echo off
- If "%1" = = "h" goto begin
- Mshta vbscript:createobject ("Wscript.Shell"). Run ("" ""%~nx0 "" H ", 0) (window.close) &&exit
- : Begin
- Rem
At this point, the full code for the bat file is as follows:
[Plain]View Plaincopyprint?
- @echo off
- If "%1" = = "h" goto begin
- Mshta vbscript:createobject ("Wscript.Shell"). Run ("" ""%~nx0 "" H ", 0) (window.close) &&exit
- : Begin
- Rem
- C:\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:
[VB]View Plaincopyprint?
- set Ws=wscript.createobject ("Wscript.Shell")
- Ws. Run "C:\abc\script.bat/start", 0
then save the file as Script.vbs and put it in "Start-All Programs-and start-up".