218
❘
CHAPTER 10
Using ironPython for AdministrAtion tAsks
FIgURE 10-14:
You can create permanent environment variables using the .NET method.
Environment variable Considerations
Some developers don’t think too hard about how the changes they make to the environment will
affect other applications. One application, which will remain nameless, actually changed the
path
environment variable and caused other applications to stop working. Users won’t tolerate such
behavior because it impedes their ability to perform useful work. In addition, companies lose a lot
of money when administrators have to devote time to fixing such problems.
The standard rules for using environment variables is that you should only read environment
variables created by others. You may find a situation where you need to change a non-standard
environment variable, but proceed with extreme caution. It’s never allowed to change a standard
environment variable, such as
USERNAME
, created by the operating system because doing so can
cause a host of problems.
If you want to have an environment variable you can change, create a custom environment variable
specifically for your application. Even if you have to copy the value of another environment variable
into this custom environment variable, you can be sure you won’t cause problems for other applica-
tions if you always use custom environment variables for your application.
STARTINg oTHER CommANd LINE APPLICATIoNS
You can start other applications using IronPython. In fact, Python provides a number of tech-
niques for performing this task. If you’ve worked with a .NET language for a while, you know
that the .NET Framework also provides several methods of starting applications. However, most
developers want to do something simple with the applications they start as subprocesses. For
example, you might want to get the operating system to perform a task that IronPython won’t
perform for you directly.
IronPython sports a plethora of methods to execute external applications. However, the simplest
of these methods is
os.popen()
. Using this method, you can quickly open an external application,
obtain any output it provides, and work with that output in your application. These three steps are
all that many developers need. Listing 10-10 shows how to use
os.popen()
to execute an external
application.
548592c10.indd 218
2/24/10 12:48:34 PM
www.finebook.ir
Do'stlaringiz bilan baham: |