1

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
user7290726
  • 31
  • 1
  • 4

0 Answers0