Skip to content

Conversation

openownworld
Copy link
Contributor

The "network" field in the heartbeat reported data is null in a Windows 10 environment.

@kongfei605
Copy link
Collaborator

这个环境network为什么是null ?

@openownworld
Copy link
Contributor Author

out, err := exec.Command("ipconfig", "-all").CombinedOutput() 在Windows 10 中文版本,out输出是gbk编码,导致go解析乱码。

@kongfei605 kongfei605 requested a review from Copilot May 30, 2025 04:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses an issue where the "network" field in the heartbeat reported data was null in a Windows 10 environment by updating the command execution process.

  • Executes "chcp 65001 >nul && ipconfig /all" via cmd to force UTF-8 encoding before running ipconfig.
  • Changes the exec.Command usage to a shell command invocation.

Comment on lines +16 to 19
cmd := exec.Command("cmd", "/c", "chcp 65001 >nul && ipconfig /all")
out, err := cmd.CombinedOutput()
if err != nil {
return
Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combining the 'chcp' and 'ipconfig' commands with '&&' may obscure which command failed; consider separating these commands to improve error diagnostics.

Suggested change
cmd := exec.Command("cmd", "/c", "chcp 65001 >nul && ipconfig /all")
out, err := cmd.CombinedOutput()
if err != nil {
return
// Execute the chcp command to set the code page to UTF-8
chcpCmd := exec.Command("cmd", "/c", "chcp 65001 >nul")
if err := chcpCmd.Run(); err != nil {
return nil, errors.New("failed to execute chcp command: " + err.Error())
}
// Execute the ipconfig command to retrieve network information
ipconfigCmd := exec.Command("cmd", "/c", "ipconfig /all")
out, err := ipconfigCmd.CombinedOutput()
if err != nil {
return nil, errors.New("failed to execute ipconfig command: " + err.Error())

Copilot uses AI. Check for mistakes.

@kongfei605 kongfei605 merged commit 7fcf5a4 into flashcatcloud:main May 30, 2025
1 of 3 checks passed
@kongfei605
Copy link
Collaborator

Thank you @openownworld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants