exec.Command
package main
import (
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("sh", "-c", "ls -al") // 执行 ls -al 命令
out, err := cmd.CombinedOutput() // 执行命令并获取输出结果
if err != nil {
fmt.Println("exec command failed:", err)
return
}
fmt.Println(string(out)) // 将输出结果转为字符串并打印到控制台
}
exec.Commandls -alCombinedOutput