1

I'm trying to make a python script that opens a separate terminal window and immediately enters a command without the user having to type anything.

I use os.system("gnome-terminal") to open the second terminal but I have no clue how to make it go ahead an enter a command. I tried os.system("gnome-terminal -e 'python ./example.py'") but it doesn't even open a second terminal, but while I have os.system("gnome-terminal") it opens one fine.

Thanks

Gray Noneya
  • 89
  • 3
  • 7
  • Have a look here : [how-can-i-spawn-new-shells-to-run-python-scripts-from-a-base-python-script](http://stackoverflow.com/questions/6469655/how-can-i-spawn-new-shells-to-run-python-scripts-from-a-base-python-script) – JazZ Jul 20 '16 at 20:00

1 Answers1

2

you can try a few ways

such as:

os.system("gnome-terminal -e 'bash -c \"sudo apt-get update; exec bash\"'")

Although on windows i opt for a sub-process, heres an example from stack:

import subprocess as sub

sub.Popen('cmd /K dir')
sub.Popen(['cmd', '/K', 'dir'])

And replace dir with whichever command you wish to use. The /k is used to keep the commandline open and run the command.

here is some other links that answer the question fairly well most of the answers actually being valid, stackoverflow

Community
  • 1
  • 1
D3181
  • 2,037
  • 5
  • 19
  • 44
  • Awesome glad it worked! could you consider marking the question as solved if it worked? – D3181 Jul 21 '16 at 10:06