我正在嘗試使用 exec.Command().Output() 來執行第 3 方工具 (SteamCMD) 來下載我運行的服務器的更新。當我通過 powershell 正常運行命令時,一切正常。
我運行的示例命令:
C:\SteamCMD\steamcmd.exe force_install_dir "C:\gameserver" login Mallachar app_update 233780
當我檢查應用程式的日志時,它作業正常。
[2022-01-05 23:13:23] 日志會話開始 [2022-01-05 23:13:23] [0,0] SetSteamID( [U:1:0] ) [2022-01-05 23: 13:23] CCMInterface::OnNetworkDeviceStateChange -- 看到設備啟動 (192.168.1.254) [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- 開始連接 Steam [2022-01-05 23:13: 23] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- 開始連接 Steam [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- 開始連接 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] 服務器說 50% 的連接應該是 websockets,我們推出了 41 - 默認使用 WebSockets。
但是,當我通過 Golang 運行它時,它不起作用
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))
}
由于網路問題,命令掛起,我得到了這個日志輸出
[2022-01-05 23:35:59] 日志會話開始 [2022-01-05 23:35:59] [0,0] SetSteamID( [U:1:0] ) [2022-01-05 23: 35:59] CCMInterface::OnNetworkDeviceStateChange -- 看到設備啟動 (192.168.1.254) [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- 開始連接到 Steam [2022-01-05 23:35: 59] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- 開始連接 Steam [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- Saw device up (192.168.1.254) [2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- 開始連接 Steam [2022-01-05 23:35:59] IPv6 HTTP連接測驗 (ipv6check-http.steamcontent.com / 0.0.0.0:80 (0.0.0.0:80)) - 超時 [2022-01-05 23:35:59] IPv6 UDP 連接測驗 (ipv6check-udp.steamcontent.com) - 失敗,沒有地址決議
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.

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?
uj5u.com熱心網友回復:
您正在向命令傳遞一個引數,即所有引數的串聯。試試這個:
out, err := exec.Command(
configData.Steamcmdpath "steamcmd.exe",
" force_install_dir", configData.Arma3path,
" login ",steamCMDUser,steamCMDPass,
" app_update", "233780",
" quit",
).Output()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/404463.html
標籤:
