Starting working directory in apps run in IDL 6.1 (and later) Runtime, VM and Embedded-license mode
THIS INFORMATION ONLY PERTAINS TO SOFTWARE VERSIONS IDL 8.5, ENVI 5.3 AND PRIOR
Topic:
This article addresses the starting working directory behavior of precompiled native IDL application Save (*.sav) files that are executed in IDL 6.1 (and later) Runtime (RT) mode, Virtual Machine (VM) mode or Runtime Embedded License (EMB) mode. Collectively, RT, VM and EMB modes are known as IDL runtime environments.
Additional information about developing and distributing IDL Save file applications can be found in the "Building IDL Applications" online manual. For more information about Callable IDL see the IDL "External Development Guide".
Starting working directory behavior in a runtime verses a non-runtime IDL execution environment
- Runtime environments
In general, if a precompiled, native IDL *.sav file application is invoked in an IDL 6.1 or later runtime environment (RT, VM, EMB), then the starting working directory of that application session will be the directory location of the *.sav application file.
Click here Table 1: Runtime environments to see an outline of runtime IDL execution environments in which running *.sav file applications causes this starting working directory behavior.
NOTE: IDL 6.0 and earlier *.sav file application starting working directory behavior
UNIX, Linux and Mac OS X
For IDL 6.0 and earlier on UNIX, Linux and Mac OS X, the default starting IDL working directory for IDL *.sav file applications that were executed in VM, RT or EMB mode, was set to the same current working directory of the UNIX shell from which the user invoked the IDL application session.
Windows
For IDL 6.0 and before on Windows the starting working directory for *.sav file applications varied depending upon the method of invocation. Additionally a current working directory is not always easy to determine in a clickable Windows environment. |
- Non-runtime environments
If the *.sav file application is restored and executed from the IDL command prompt, IDL source code or equivalent, then the just the execution of the *.sav file application will not automatically alter the working directory.
Click here Table 2: Non-runtime environments to see an outline of non-runtime IDL execution environments in which running *.sav file applications do not cause the starting working directory to change.
Advantages of a Consistent Starting Working Directory Behavior in an IDL Runtime environment
IDL *.sav file applications are often distributed with or may create required files that exist relative to the application *.sav file itself. Being able to consistently reference the location of files relative to the main *.sav application file, and across platforms, makes it easy to keep track of associated files regardless of the installation location on a user's machine.
Changing the Default Starting Working Directory
However, if you require your IDL *.sav file application session to set the working directory to a location different than the directory that contains your *.sav file, your IDL program will need to explicitly reset the IDL current working directory (CD) to the desired location. Below are some examples that illustrate changing the working directory for your IDL application to a non-default location.
Discussion:
Starting Working Directory Behavior of *.sav File Applications, by IDL Execution Environment
TABLE 1: Runtime environments |
Behavior:
The starting working directory is automatically set to the directory location of the IDL *.sav application file in the following IDL execution environments. |
IDL Execution Environment |
Comments |
IDL Runtime (RT) |
For details about working with IDL Runtime applications see the "Runtime Licensing" section of the "Building IDL Applications" manual. |
IDL Virtual Machine (VM) |
For details about working with IDL VM see "The IDL Virtual Machine" section of the "Building IDL Applications" manual. |
IDL Runtime Embedded License mode (EMB) |
For details about working with embedded licensing see the "Embedded Licensing" section of the "Building IDL Applications" manual. |
Callable IDL using IDL_RuntimeExec() |
Using IDL_RuntimeExec() is equivalent to launching IDL *.sav file application in RT mode. (Contrast this starting working directory behavior to Callable IDL using IDL_Execute() or IDL_ExecuteStr().)
For more information about Callable IDL see the IDL "External Development Guide". |
[ back to top ^ ]
Table 2: Non-runtime environments |
Behavior:
The starting working directory is not altered by the (restore and) execution of an IDL *.sav file application in the following IDL execution environments. |
IDL Execution Environment |
Comments |
Development IDL session
(Restore/execute the *.sav file application at the IDL command prompt or through an IDL source code program call) |
When developing applications that will be executed in the IDL runtime enviroment (VM, RT or EMB mode), be aware of the difference in the starting working directory behavior of the development verses the runtime execution environments. |
Non-interactive IDL Batch job session
(Restore/execute the *.sav file application using IDL batch script commands or through source code program calls via a batch script command) |
IDL batch file program commands are equivalent to issuing commands at the IDL command prompt.
For more information about using IDL Batch Job see the "Executing Batch Jobs in IDL" section of the "Using IDL" manual. |
IDLDrawWidget ActiveX Control
(Restore/execute the *.sav file application using ExecuteStr()) |
Commands issued through the IDLDrawWidget ExecuteStr() function is equivalent to issuing commands at the IDL command prompt.
For more information about the IDLDrawWidget ActiveX Control, see the IDL "External Development Guide". |
Callable IDL using IDL_Execute() or IDL_ExecuteStr()
(Restore/execute the *.sav file application using IDL_Execute() or IDL_ExecuteStr()) |
Commands issued through IDL_Execute() or IDL_ExecuteStr() is equivalent to issuing commands at the IDL command prompt -- even if the Callable IDL session is initialized with the IDL_INIT_RUNTIME option. (Contrast this starting working directory behavior to Callable IDL using IDL_RuntimeExec().)
For more information about Callable IDL see the IDL "External Development Guide". |
[ back to top ^ ]
Example approaches for changing the starting working directory for *.sav file applications launched in an IDL runtime environment
- Example 1: Setting the IDL working directory to a hard-coded directory location (all platforms)
If your IDL VM, RT or EMB *.sav file application requires that the working directory always starts in a fixed, known location, the programmer could simply set the working directory to a hard-coded path. For example, the initial IDL command for an application might look like:
The working directory can also be set to a location relative to the *.sav application file. For example, to set the working directory to a directory called 'myadjdir' that is adjacent to the *.sav application file location:
Be certain that the hard-coded directory path exists on the user's machine or an error will occur.
[ back to top ^ ]
- Example 2: Setting the IDL working directory to a system environment variable in the environment from which the application was executed (all platforms)
This approach has the advantage of allowing the working directory to be specified from outside of the application code, via a system environment variable definition. For example, the initial IDL commands for an application might look like:
sDir=GETENV('MYAPP_STARTDIR')
IF sDir NE '' AND FILE_TEST(sDir,/DIRECTORY) THEN CD,sDir
Using this approach on Windows, an IDL *.sav file application installer could automatically set the system environment "MYAPP_STARTDIR" in the system registry to the directory location of application files. Or you might have the user manually define the system environment variable as part of the installation process.
On UNIX, the "MYAPP_STARTDIR" system environment variable could be defined in a user's shell setup (.*rc) file. Another strategy might be for the system environment variable to be defined within a shell script program that is created at installation time, setting the "MYAPP_STARTDIR" to the correct directory location.
[ back to top ^ ]
- Example 3: Setting the IDL working directory to the UNIX shell current working directory (UNIX / Linux / Mac OS X)
On UNIX (as well as Linux and Mac OS X), in IDL 6.0 and earlier, the default starting working directory for IDL *.sav file applications executed in VM, RT or EMB mode, was set to the same current working directory of the UNIX shell from which the user invoked the IDL application session. In order to make a *.sav file application that is invoked in IDL *6.1* have a starting working directory behavior that is similar to IDL *6.0* behavior, a programmer could issue the following command at the beginning of the IDL program:
This command uses the $PWD environment variable value (which specifies the shell's current working directory) of the shell that invoked the IDL session, in order to set the working directory location.
[ back to top ^ ]
Solution:
[Edit this field in the IDL-based Tech Tip Editor, v62]