如何更改代码而不是显示它 (fmt.Printf) 以执行命令 (exec.Command)
现在我有这个:
// Print keys
fmt.Printf("%x %34s %34s\n", padded, uaddr.EncodeAddress(), caddr.EncodeAddress())
如何给 'g' 和 'h' 赋值:
v := "cmd"
n := "/C"
a := "testcmd"
b := "-connect=127.0.0.1"
c := "-port=3333"
d := "-user=username"
e := "-password=password"
f := "importaddress"
g := "AddressHere"
h := "MoreInfo"
z := exec.Command(v, n, a, b, c, d, e, f, g, h)
if err := z.Run(); err != nil {
fmt.Println("Error: ", err)
}
我需要给这个变量赋值:
h := fmt.Printf("%x\n", padded)
g := fmt.Printf("%34s\n", uaddr.EncodeAddress())
g := fmt.Printf("%34s\n", caddr.EncodeAddress())
用不同的变量执行命令两次
最佳答案
您可以使用fmt.Sprintf()
例子:
g := fmt.Sprintf("%s", uaddr.EncodeAddress())
Sprintf 根据格式说明符格式化并返回结果字符串。然后,您可以为您的变量使用相同的值。
关于go - 从 fmt.Printf 更改为 exec.Command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57821387/