Friday, October 10, 2025
HomeGolangThe results of Prime command carried out by go os/exec behave inconsistently...

The results of Prime command carried out by go os/exec behave inconsistently throughout totally different golang variations – Technical Dialogue


bundle fundamental
  
import (
        "fmt"
        "os/exec"
        "strconv"
        "strings"
)

func  MyTop(topNum uint, args ...string) (out []byte, err error) {
        lineNumStr := strconv.FormatUint(uint64(topNum), 10)
        shCmd := []string{"prime", "-n", "1", "-b"}
        shCmd = append(shCmd, args...)
        shCmd = append(shCmd, "|", "head", "-n", lineNumStr)

        cmd := exec.Command("bash", "-c", strings.Be a part of(shCmd, " "))
        buf, err := cmd.Output()
        return buf, err
}

func fundamental() {
   buf_mem, _ := MyTop(20, "-o", "%MEM")
   fmt.Printf("prime memeory >n %s", buf_mem)
    return
}

the output is totally different in go1.15.7 and go1.19.10:

what occurred right here in go1.19.10?

I doubt go model has something to do with this. What occurs on that second OS (node1 not node-77) whenever you simply run prime in a shell? You could possibly additionally rule out the go model by compiling on an OS with go model 1.15.7 after which utilizing that binary on node1 to see if the output is totally different (I’m assuming you’re simply utilizing go run . right here, not a binary).

the outcomes have been the identical once I simply run ‘prime -n 1 -b -o %MEM’ commnad in a shell on each host(node1, node-77)

I compiled a binary on a number with go model 1.19.10(node 1), and run it on node-77, which go model is go1.15.7, and the result’s that it behaved regular,

Nicely, the model of go that’s put in on node-77 has no bearing on how the binary performs, in order that factors to the command itself. Verify your .bashrc for settings? I’m not tremendous accustomed to prime or else I might need extra particular troubleshooting steps there. Are you able to simply specify the columns within the output?

Nicely, my .bashrc is kind of easy, nothing particular in it, they’re all default settings.

Are you able to simply specify the columns within the output?

certain, I’ll have a strive

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments