Home > OS >  Golang exec.Command prevents socket/internet access for launched service on Windows?
Golang exec.Command prevents socket/internet access for launched service on Windows?

Time:01-07

I am trying to use exec.Command().Output() to execute a 3rd party tool (SteamCMD) to download updates for a serverI run. When I run the commands normally through powershell, everything runs fine.

Example command I run:

C:\SteamCMD\steamcmd.exe force_install_dir "C:\gameserver" login Mallachar app_update 233780

When I check the logs of the application, it works fine.

[2022-01-05 23:13:23] Log session started [2022-01-05 23:13:23] [0,0] SetSteamID( [U:1:0] ) [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- Start connecting to Steam [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- Start connecting to Steam [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- Start connecting to Steam [2022-01-05 23:13:23] [0,0] SetSteamID( [U:1:879488788] ) [2022-01-05 23:13:23] [0,0] SetSteamID( [U:1:879488788] ) [2022-01-05 23:13:23] [0,0] Server says 50% of connections should be websockets, we rolled 41 - using WebSockets as default.

However, when I run this through Golang, It doesn't work


import (
    "fmt"
    "os/exec"
    "strings"
)

const armA3ServerID string = " app_update 233780"

func steamSession(configData Server, steamCMDUser string, steamCMDPass string) {
    var steamCMDCommand strings.Builder
    steamCMDCommand.WriteString(" force_install_dir \""   configData.Arma3path   "\" ")
    steamCMDCommand.WriteString(" login "   steamCMDUser   " "   steamCMDPass   " ")
    steamCMDCommand.WriteString(armA3ServerID)

    steamCMDCommand.WriteString("  quit")

    out, err := exec.Command(configData.Steamcmdpath "steamcmd.exe", steamCMDCommand.String()).Output()

    if err != nil {
        fmt.Printf("Error Is", err)
    }

    fmt.Printf("%s\n", string(out))
}

The command hangs because of networking issues, and I get this log output

[2022-01-05 23:35:59] Log session started [2022-01-05 23:35:59] [0,0] SetSteamID( [U:1:0] ) [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- Start connecting to Steam [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- Start connecting to Steam [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- Start connecting to Steam [2022-01-05 23:35:59] IPv6 HTTP connectivity test (ipv6check-http.steamcontent.com / 0.0.0.0:80 (0.0.0.0:80)) - TIMEOUT [2022-01-05 23:35:59] IPv6 UDP connectivity test (ipv6check-udp.steamcontent.com) - FAILED, no addresses resolved

When I terminate the background instance of the steamcmd running, my GoLang program prints out the output which showed it did tried to execute, but just hung at the connection part.

enter image description here

So As far as I can tell, it seems like when I used exec.Command, the services I launch with it do not have internet/socket access? I tried running as admin, but didn't seem to fix anything. Not sure if maybe there is a step I am missing or something I need to change flag wise.

So the command does run, the backend application runs, but it fails to resolve the address/make a connection. So seems like my command itself is not the issue, but something with GoLang exec.Command?

CodePudding user response:

You are passing a single argument to the command, the concatenation of all the arguments. Try this instead:

   out, err := exec.Command(
     configData.Steamcmdpath "steamcmd.exe",
     " force_install_dir", configData.Arma3path,
     " login ",steamCMDUser,steamCMDPass,
      " app_update", "233780",
     " quit",
  ).Output()
  •  Tags:  
  • Related