How do I pass inputs to parted command to resize partition

100 Views Asked by At

I am trying to execute exec.Command like cmd := exec.Command("parted", "-s", "/dev/vdb", "resizepart", "2", "20GB") to extend partition of vdv. vdv has only 2 partitions and I want second partition to be executed. I am not able to do so. Have written the below code:

func main() {
    r, w := io.Pipe()
    cmd := exec.Command("parted", "/dev/vdb",  "resizepart", "2", "25G")
    cmd.Stdin = r
    go func() {
        fmt.Fprintf(w, "Fix\n")
        fmt.Fprintf(w, "2\n")
        fmt.Fprintf(w, "35\n")
        w.Close()
    }()
    err := cmd.Start()
    if err != nil {
        fmt.Printf(err.Error())
    }
    err = cmd.Wait()
    if err != nil {
        fmt.Printf(err.Error())
    }
}

parted command will throw warning first and for that we need Fix as input to continue.

0

There are 0 best solutions below