[Tutor] Subprocess help
Danny Yoo
dyoo at hashcollision.org
Sun Sep 21 23:18:47 CEST 2014
> "Semantically, the command above means:
> execute "./octosetupBROADCASTER-linux_i386.bin" in an environment
> that binds BYPASSROOT to "yes"."
>
> Does the above mean "BYPASSROOT" is an environmet variable? Is this created and set by default by the system or is it created and set by "octosetupBROADCASTER-linux_i386.bin?"
The word "system" is ambiguous. Let's be specific.
The actor here is the command-line shell.
Assuming that you are using the 'bash' command-line shell, see:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html
http://www.gnu.org/software/bash/manual/bash.html#Command-Execution-Environment
http://www.gnu.org/software/bash/manual/bash.html#Environment
for the background information.
The particular usage you are doing here at your command line shell:
$ BYPASSROOT=yes ./octosetupBROADCASTER-linux_i386.bin
is a concrete instance of augmenting the environment with a temporary
set of variables, as described in Section 3.7.4 of the Bash
documentation:
"""The environment for any simple command or function may be
augmented temporarily by prefixing it with parameter assignments, as
described in Shell Parameters. These assignment statements affect only
the environment seen by that command."""
I do need to cut in and editorialize: a little knowledge is dangerous.
You're asking questions that suggest that you have a passing
familiarity with Unix, but not a deep one. Given what you appear to
be doing, this frightens me.
I am not joking; this is not a laughing matter. Please talk to your
local friendly Unix system administrator, and take a real Unix system
administration class. In the United States, you can visit one of the
USENIX groups:
https://www.usenix.org/legacy/membership/groups_usa.html
I'm not so familiar with the situation outside the US, but I'm pretty
sure similar groups can be found.
> The code you suggested...
>
> "envCopy = os.environ.copy()
> envCopy['BYPASSROOT'] = 'yes'
> subprocess.Popen(["./octosetupBROADCASTER-linux_i386.bin"], env=envCopy)"
>
> This copies the systems environment variables and stores them in the variable "envCopy?" What do the "[ ]'s" mean? Are the variables stored in an array or list and by enclosing "BYPASSROOT" in brackets, we are ultimately selecting "BYPASSROOT" and assinging its value to "yes?"
Please read:
https://docs.python.org/2/tutorial/datastructures.html#dictionaries
More information about the Tutor
mailing list