-2

I just learned python. I want to make a python program to setup my ubuntu linux distribution.

How to simulate to enter "apt-get install firefox" and an enter key?

When installation is sucessful, "finished!" shows on the terminal. How my python program can know key word "finished" is displayed?

5
  • Take a look at the subprocess module for executing shell commands from Python. Commented Jan 16, 2017 at 22:37
  • Possible duplicate of mod_python equivalent to php exec() command Commented Jan 16, 2017 at 22:39
  • 1
    Check out subprocess.Popen examples, especially the ones that use communicate. It will run a program and give you its output. Commented Jan 16, 2017 at 23:01
  • You needn't 'shell out' to install a package using apt. There is an apt package available. You can just install the package using normal python code. Disclaimer I haven't tried it. Commented Jan 16, 2017 at 23:32
  • subprocess is what I want. Thanks! Commented Jan 16, 2017 at 23:50

1 Answer 1

0

The terminal is a just way for a person to issue commands to the operating system and for the operating system to show results back to the person. With Python and other languages, you can issue commands to the operation system without a terminal and programmatically process responses received back from the OS or the program you had the OS run. For python, use the subprocess module. For example, you might write something like subprocess.POpen(["apt-get", "install", "firefox"], ...). I am on Windows, so cannot test a specific example on Ubuntu. Read the docs and experiment with the examples and options.

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

Comments

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.