go – Change from fmt.Printf to exec.Command-ThrowExceptions

Exception or error:

How can I change the code instead of showing it (fmt.Printf) to execute a command (exec.Command)

Now I have this:

// Print keys
fmt.Printf(“%x %34s %34s\n”, padded, uaddr.EncodeAddress(), caddr.EncodeAddress())

How to give a variable value to ‘g’ and ‘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)
    }

I need to give this variable valie:

h := fmt.Printf("%x\n", padded)
g := fmt.Printf("%34s\n", uaddr.EncodeAddress())
g := fmt.Printf("%34s\n", caddr.EncodeAddress()) 

execute the command twice with different variables

How to solve:

You can use fmt.Sprintf()

Example:

g := fmt.Sprintf("%s", uaddr.EncodeAddress())

Sprintf formats according to a format specifier and returns the resulting string. You can then use this same value for your variables.

Leave a Reply

Your email address will not be published. Required fields are marked *