执行外部命令并返回其输出

I'm trying to execute a linux command and convert the output to an int. This is my current code:

package main

import (
    "os/exec"
    "os"
    "strconv"
    _"fmt"
    "log"
    "bytes"
)

func main(){

    cmd := exec.Command("ulimit", "-n")
    cmdOutput := &bytes.Buffer{}
    cmd.Stdout = cmdOutput
    err := cmd.Run()
    if err != nil {
      os.Stderr.WriteString(err.Error())
    }

    count, err := strconv.Atoi( string(cmdOutput.Bytes()) )
    if err != nil {
        log.Fatal(err)
    }

    if count <= 1024 {
        log.Fatal("This machine is not good for working!!!")
    }
}

This is my current error:

2018/10/12 14:37:27 exec: "ulimit -n": executable file not found in $PATH

I don't understand what this error means and how I can fix it.

There is no ulimit program in linux that you can run.

ulimit is a builtin of a shell. So you need to run a shell and have the shell run its internal ulimit command.

cmd := exec.Command("/bin/sh", "-c" "ulimit -n")

you will also have to remove the newline from the output of the ulimit command, e.g.

count, err := strconv.Atoi( strings.Trim(string(cmdOutput.Bytes()),"
"))

A better alternative is to retreive these limits via the syscall API in go, see How to set ulimit -n from a golang program? - the accepted answer first gets and prints the current limit.