in reply to launch a program and then write to the program
As you've already been told in the CB, perlipc and perlopentut are your ports of call. For R specifically, there is Statistics::R. Expect doesn't work under Windows unfortunately.