Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38742

Re: how to call shell?

From Albert Hopkins <marduk@letterboxes.org>
References <CA+YdQ_6G8hmtHHNHen1XZeMsO+gp91xf4fdFO3bkefoq92OpMA@mail.gmail.com>
Subject Re: how to call shell?
Date 2013-02-12 06:18 -0500
Newsgroups comp.lang.python
Message-ID <mailman.1697.1360667913.2939.python-list@python.org> (permalink)

Show all headers | View raw



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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: how to call shell? Albert Hopkins <marduk@letterboxes.org> - 2013-02-12 06:18 -0500

csiph-web