From Python to Shell

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NightHawk

    #1

    From Python to Shell

    Im not a total noob but i don't know the command and the module to go
    from python to the default shell.
    (not from interactive mode - $python)

  • Harold Fellermann

    #2
    Re: From Python to Shell

    > Im not a total noob but i don't know the command and the module to go[color=blue]
    > from python to the default shell.[/color]

    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(comma nd_string):
    execute command string in a subshell. result is the return value of
    command_str
    subprocess.Pope n(command):
    starts command as a subprocess and allows you to "communicat e" 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 -

    Comment

    • Fredrik Lundh

      #3
      Re: From Python to Shell

      NightHawk wrote:
      [color=blue]
      > Im not a total noob but i don't know the command and the module to go
      > from python to the default shell.[/color]

      I'm not sure what you mean by "go to", but if you want to start an
      interactive OS shell from inside Python, you can do:
      [color=blue][color=green][color=darkred]
      >>> import os
      >>> os.system(os.en viron["SHELL"])[/color][/color][/color]

      on Unix, and
      [color=blue][color=green][color=darkred]
      >>> import os
      >>> os.system(os.en viron["comspec"])[/color][/color][/color]

      on Windows.

      </F>

      Comment

      Working...