如何在golang中为exec.command添加空格 [英] How do you add spaces to exec.command in golang
本文介绍了如何在golang中为exec.command添加空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用exec.command启动一个带空格的文件?添加引号似乎不起作用,或者%20而不是空格。
How do I use exec.command to start a file with spaces? Adding quotes doesn't seem to work, neither does " or %20 instead of the spaces.
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)
}
}
推荐答案
p>
This works, but only in windows
cmd := exec.Command("rundll32.exe", "url.dll,FileProtocolHandler", Filename)
这篇关于如何在golang中为exec.command添加空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文