From Python to Shell

Harold Fellermann dadapapa at googlemail.com
Thu Jun 8 16:25:00 CEST 2006


> Im not a total noob but i don't know the command and the module to go
> from python to the default shell.

there are several ways depending on what exactly you want to achieve:

sys.exit(return_value):
    terminates the python process and gives controll back to the shell
os.system(command_string):
    execute command string in a subshell. result is the return value of
command_str
subprocess.Popen(command):
    starts command as a subprocess and allows you to "communicate" with
    that process, i.e. lets you send something to its stdin and
retrieve data
    from its stdout and stderr streams. have a look at the docs of that
module
    for more information.

- harold -




More information about the Python-list mailing list