For a project I am working on I want to automate a series of commands to a separate terminal window so that I can control other programs that use the terminal, or just run general Linux commands.
So far I have tried using subprocess to open a new terminal window using
proc = subprocess.Popen('gnome-terminal')
I have also been able to open programs, for example nano.
proc = subprocess.Popen(['gnome-terminal', '--command=nano'])
But then I can't send more commands to the terminal, meaning I can control it as a user, but I can't automate what it does with python. I have tried using subprocess and pipes to send more commands, but that hasn't worked. I also looked into os.system() but couldn't seem to find a solution.
For a quick example
1) Python opens a new terminal
2) send it 'echo this is a test"
3) send it 'ping -c 10 192.168.x.x >> pingout.txt'
4) in the terminal 'nano pingout.txt'
5) write 'this is a test'
6) then '^X', 'y', and Return to save the edited file
Then the python program would continue on.