Re: how to call shell?

2013-02-12 Thread Albert Hopkins


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
-- 
http://mail.python.org/mailman/listinfo/python-list


how to call shell?

2013-02-11 Thread contro opinion
 import os
 os.system(i=3)
0
 os.system(echo $i)

0

why i can't get the value of i ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to call shell?

2013-02-11 Thread Tim Roberts
contro opinion contropin...@gmail.com wrote:

 import os
 os.system(i=3)
0
 os.system(echo $i)

0

why i can't get the value of i ?

Each invocation of os.system creates a brand new shell that starts, runs,
and terminates.  Your first command adds a variable i to the environment
for that shell, but the variable is deleted when the shell procsess
terminates.
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list