I need to copy all the input provided by the user for the child process during its execution. I have tried to scan the cmd.Stdin for the copy of input but can't get it. Am I missing something here?
func main(){
cmd:= exec.Command("python", "-i")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
buff := bufio.NewScanner(cmd.Stdin)
go func(){
for buff.Scan(){
fmt.Println(buff.Text())
}
}()
_ = cmd.Run()
}
I think you'll actually need to capture the input, and pass it to the subprocess...
func main(){
cmd := exec.Command("python", "-i")
stdin, err := cmd.StdinPipe()
if err != nil {
panic(err)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
buff := bufio.NewScanner(os.Stdin)
go func(){
for buff.Scan(){
input := buff.Text()
fmt.Println(input)
io.WriteString(stdin, input)
}
}()
cmd.Start()
cmd.Wait()
}