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

1

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome glad it worked! could you consider marking the question as solved if it worked?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.