如何使用exec.command启动带有空格的文件?添加引号似乎无效,“或%20代替空格也不起作用。
package main import ( "fmt" "os/exec" ) func main() { StartProcess("C:\\File With Spaces.txt") } func StartProcess(Filename string) { Filename = "\"" + Filename + "\"" cmd := exec.Command("cmd","/C start",Filename) err := cmd.Start() if err!=nil{ fmt.Println(err) } }
这有效,但仅在Windows中
cmd := exec.Command("rundll32.exe", "url.dll,FileProtocolHandler", Filename)