Re: call shell from python

Discussion in 'Python' started by Chris Rebert, Feb 12, 2013.

  1. Chris Rebert

    Chris Rebert Guest

    On Mon, Feb 11, 2013 at 9:13 PM, contro opinion <> wrote:
    >>>> import os
    >>>> os.system("i=3")

    > 0
    >>>> os.system("echo $i")

    >
    > 0
    > how can i get the value of i?


    Your example is too heavily contrived for me to give a much more
    specific/useful answer than "use the `subprocess` module":
    http://docs.python.org/2/library/subprocess.html#using-the-subprocess-module

    Of course, if all you want to do is manipulate environment variables,
    then there's `os.environ`:
    http://docs.python.org/2/library/os.html#os.environ

    Good luck, my pseudonymous contrarian compadre.
    – Chris
     
    Chris Rebert, Feb 12, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,847
    Jonathan Bromley
    Feb 18, 2005
  2. Christian Heimes
    Replies:
    0
    Views:
    623
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,129
    Philipp Pagel
    Feb 27, 2008
  4. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    887
    D'Arcy J.M. Cain
    Feb 27, 2008
  5. edwithad

    Bash shell to Python shell?

    edwithad, Sep 28, 2009, in forum: Python
    Replies:
    4
    Views:
    1,791
Loading...

Share This Page