I use go-openvpn as openvpn client to connect server.
I use the example code for desk to build the ‘test.exe’, when I run it with admin privilege, it quickly pop-up and close cmd window 3 times. It closes too quick to see what’s content in the window.
I recorded a video of the phenomenon
How to stop pop-up window?
Here is my example code, I only add a timer to close the session. go build -ldflags "-w -s -H windowsgui" -o test.exe
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
"time"
"github.com/mysteriumnetwork/go-openvpn/openvpn3"
)
type callbacks interface {
openvpn3.Logger
openvpn3.EventConsumer
openvpn3.StatsConsumer
}
type loggingCallbacks struct {
}
func (lc *loggingCallbacks) Log(text string) {
lines := strings.Split(text, "n")
for _, line := range lines {
fmt.Println("Openvpn log >>", line)
}
}
func (lc *loggingCallbacks) OnEvent(event openvpn3.Event) {
fmt.Printf("Openvpn event >> %+vn", event)
}
func (lc *loggingCallbacks) OnStats(stats openvpn3.Statistics) {
fmt.Printf("Openvpn stats >> %+vn", stats)
}
var _ callbacks = &loggingCallbacks{}
// StdoutLogger represents the stdout logger callback
type StdoutLogger func(text string)
// Log logs the given string to stdout logger
func (lc StdoutLogger) Log(text string) {
lc(text)
}
func main() {
var logger StdoutLogger = func(text string) {
lines := strings.Split(text, "n")
for _, line := range lines {
fmt.Println("Library check >>", line)
}
}
openvpn3.SelfCheck(logger)
bytes, err := ioutil.ReadFile("./client1.ovpn")
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
config := openvpn3.NewConfig(string(bytes))
session := openvpn3.NewSession(config, openvpn3.UserCredentials{}, &loggingCallbacks{})
session.Start()
time.Sleep(20 * time.Second)
session.Stop()
os.Exit(0)
}
Here is my client ovpn config file
client
dev tunkj
proto tcp
nobind
remote address port
fast-io
persist-key
verb 3
script-security 3
connect-retry 3 6
connect-timeout 6
ping 5
ping-restart 20
up-delay
<auth-user-pass>
username
password
</auth-user-pass>
auth-nocache
topology subnet
<ca>
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
</ca>
I use this command go build -ldflags "-w -s -H windowsgui" -o test.exe
to disable cmd window.
I expecting to stop pop-up window when starting connection. Or the way to record the content in cmd window, so i can locate what cause this.
000 Degree is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.