Commande argument

Good morning,

My Go program allows you to create this command to call another python program

The python program generates Random data and launches a machine learning clustering algorithm (kmeans)

My question how to pass my input data (dataset) randomly generated in this command:
exec.Command(“ipython”, “-c”, "import kmeans; model=kmeans.KMeans(K=5, max_iters=100, plot_steps=False);model.predict(data=data)

Cordially.

exec.Command will quote the arguments correctly. This works:

package main

import (
    "bytes"
    "fmt"
    "log"
    "os/exec"
)

func main() {
    cmd := exec.Command("python3.7", "-c", "print(\"foo\"); print(1 + 2)")
    var out bytes.Buffer
    cmd.Stdout = &out
    err := cmd.Run()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%q\n", out.String())
}

Output:

"foo\n3\n"