demo: oslookpath; syscall.Lstat/Stat

This commit is contained in:
xushiwei
2024-07-11 19:21:04 +08:00
parent a5ff25b0fe
commit aac820a8d5
3 changed files with 42 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
package main
import (
"fmt"
"os/exec"
"runtime"
)
func main() {
ls := "ls"
if runtime.GOOS == "windows" {
ls = "dir"
}
lspath, _ := exec.LookPath(ls)
if lspath != "" {
ls = lspath
}
fmt.Println(ls)
}