path ,_:= os.Getwd()
返回当前文件路径C:\www\go\src\hellopath := filepath.Dir(os.Args[0])
同上_, s, _, _ := runtime.Caller(0)
当前文件全路径 C:\www\go\src\hello\hello.exes, _ := exec.LookPath(os.Args[0])
同上f1 := filepath.Join(path,"test","1.txt")
连接路径C:\www\go\src\hello\test\1.txt
os.Exit(0) 程序终止
f,:=os.Hostname() //主机名 XiaoxinAir14
f,:=os.UserHomeDir() //用户目录 C:\Users\yoby
u,_:=user.Current() //os/user
home:=u.HomeDir //用户目录 C:\Users\yoby
username:=u.Username //用户名 XIAOXINAIR14\yoby
pid := os.Getpid() 当前进程
fmt.Printf(“进程 PID: %d n”, pid)
j, _ := os.FindProcess(pid)
j.Kill() 关闭程序
var out [512]byte 输入
os.Stdin.Read(out[:])
string(out[:])
c:=ipconfig/all
//执行cmd
cmd:= exec.Command(“cmd.exe”, “/C”, c)
//cmd = exec.Command(“/bin/sh”, “-c”, cmdstring)
cmd.Run() //执行命令不返回
更新时间:2024-12-05 13:26