fmt.Print("Enter valid nbd: ")
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('n')
if err != nil {
fmt.Println("An error occured while reading input. Please try again", err)
return
}
input = strings.TrimSuffix(input, "n")
cmd = exec.Command("/bin/bash", "-c", "qemu-nbd -c /dev/", input, "/tmp/var/lib/vz/images/201/vm-201-disk-0.qcow2")
cmd.Run()
cmd = exec.Command("/bin/bash", "-c", "mount /dev/", input, "p1 /mnt")
cmd.Run()
I want to pass user input, for example nbd7, to both exec.Command as I mentioned.
input = strings.TrimSuffix(input, "n")
mount := qemu-nbd -c /dev/input /tmp/CentOS-7.7.1908-x64.qcow2
cmd = exec.Command("/bin/bash", "-c", mount, "echo stdout; echo 1>&2 stderr")
I have modified abit of my code. Any proper way that I can pass my input value into mount variable’s value? /dev/input definitely not working.
2
Answers
Thanks everyone, the code is working correctly in this way.
It is possible. Code is correct, you can use
cmd.String
to print executed command. There is most likely error during execution.I would recommend to use
cmd.Output()
andcmd.StderrPipe()
for debugging.