英文:
Golang exec.Command prevents socket/internet access for launched service on Windows?
问题
我正在尝试使用exec.Command().Output()
来执行一个第三方工具(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 -- 检测到设备上线 (192.168.1.254)
[2022-01-05 23:13:23] CCMInterface::OnNetworkDeviceStateChange -- 开始连接到Steam
[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] [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运行时,它不起作用。
package main
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("错误:%v", 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 -- 检测到设备上线 (192.168.1.254)
[2022-01-05 23:35:59] CCMInterface::OnNetworkDeviceStateChange -- 开始连接到Steam
[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] 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) - 失败,未解析到地址
当我终止后台运行的steamcmd实例时,我的GoLang程序打印出了输出,显示它确实尝试执行,但在连接部分卡住了。
所以据我所知,似乎当我使用exec.Command
时,我启动的服务没有互联网/套接字访问权限?我尝试以管理员身份运行,但似乎没有解决任何问题。不确定是否有步骤我遗漏了或者是否需要更改标志。所以命令确实运行,后端应用程序运行,但无法解析地址/建立连接。所以似乎我的命令本身不是问题,而是与GoLang的exec.Command
有关的问题。
英文:
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.
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?
答案1
得分: 3
你正在将一个参数传递给命令,该参数是所有参数的连接。请尝试使用以下代码替代:
out, err := exec.Command(
configData.Steamcmdpath+"steamcmd.exe",
"+force_install_dir", configData.Arma3path,
"+login", steamCMDUser, steamCMDPass,
"+app_update", "233780",
"+quit",
).Output()
英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论