outputting a command to the terminal?
Diez B. Roggisch
deets at nospam.web.de
Sun Aug 13 17:47:35 EDT 2006
John Salerno schrieb:
> Here's my new project: I want to write a little script that I can type
> at the terminal like this:
>
> $ scriptname package1 [package2, ...]
>
> where scriptname is my module name and any subsequent arguments are the
> names of Linux packages to install. Running the script as above will
> create this line:
>
> sudo aptitude install package1 package2 ...
>
> It will run that line at the terminal so the package(s) will be installed.
>
> Now, the extra functionality I want to add (otherwise I would just
> install them normally!) is to save the package names to a text file so I
> can now the names of programs I've manually installed, if I ever want to
> check the list or remove packages.
>
> So creating the proper bash command (sudo aptitude install ...) is easy,
> and writing the names to a file is easy. But I have two questions:
>
> 1. First of all, does Linux keep track of the packages you manually
> install? If so, then I won't have to do this at all.
>
> 2. Assuming I write this, how do output the bash command to the
> terminal? Is there a particular module that Python uses to interact with
> the terminal window that I can use to send the install command to the
> terminal?
You don't put a command to the terminal. The shell executes commands.
But it is mainly just a program itself - it can spawn subprocesses and
make these execute the actual commands. so - the module you need is most
probably subprocess.
Diez
More information about the Python-list
mailing list