Re: how to call shell?

Discussion in 'Python' started by Albert Hopkins, Feb 12, 2013.

  1. On Tue, Feb 12, 2013, at 12:12 AM, contro opinion wrote:
    > >>> import os
    > >>> os.system("i=3")

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

    >
    > 0
    > >>>

    > why i can't get the value of i ?


    Whenever you call os.system, a new shell is created and the command is
    run, system() then waits for the command to complete.
    You don't see i because your two system() calls are in two different
    processes:

    python> import os
    python> os.system('echo $$')
    24294
    0
    python> os.system('echo $$')
    24295
    0

    However, ths (e.g.) would work:

    python> os.system('i=3; echo $i')
    3
    0

    HTH,
    -a
    Albert Hopkins, 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,695
    Jonathan Bromley
    Feb 18, 2005
  2. Christian Heimes
    Replies:
    0
    Views:
    597
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,074
    Philipp Pagel
    Feb 27, 2008
  4. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    862
    D'Arcy J.M. Cain
    Feb 27, 2008
  5. Samuel A. Falvo II
    Replies:
    0
    Views:
    481
    Samuel A. Falvo II
    Oct 8, 2008
Loading...

Share This Page