Go lang将os.File输出转换为String

How to convert Os.File output into string instead of printing to shell. I am using github.com/kr/pty library to execute commands.

How can convert the output to sting instead of printing to console.

f belongs to Os.File in below example. How to convert it to string.

package main

import (
    "github.com/kr/pty"
    "io"
    "os"
    "os/exec"
)

func run_command(cmd string){
    c := exec.Command("/bin/sh", "-c", cmd)
    f, err := pty.Start(c)
    if err != nil {
        panic(err)
    }
    io.Copy(os.Stdout, f)
}

func main() {
    run_command("ls -lrt");
}

Instead of

io.Copy(os.Stdout, f)

you can do

var buf bytes.Buffer
io.Copy(&buf, f)
asString := string(buf.Bytes())