Windows Batch Script Example

This example creates a Normalized Difference Vegetation Index (NDVI) image from an input QuickBird image, by invoking envitaskengine through a Windows batch script.

  1. Start a DOS command window.
  2. Create a scratch directory with write permission, where temporary output can be written. Change to that directory.
  3. cd C:\

    mkdir sandbox

    cd sandbox

  4. Run the script with the required arguments, as follows. Run the script from the directory that has write permission. An NDVI image will be created in the sandbox directory. If you do not want to escape the backslashes with additional backslashes (as shown below), replace them with forward slashes instead.
  5. "C:\\idl_install_dir\\examples\\taskengine\\example_spectral_index.bat" "C:\\envi_install_dir\\data\\qb_boulder_msi" "Normalized Difference Vegetation Index" "C:\\sandbox\\ndvi.dat"

    Where idl_install_dir and envi_install_dir are the IDL and ENVI installation paths on your system.

Copy of Script

Here is a copy of the example_spectral_index.bat script. Use this as a template for writing your own script, changing the arguments as needed.

@echo off

 

::-------

:: Usage

::-------

 

GOTO START

 

:USAGE

   echo.

   echo Usage:

   echo.

   echo example_spectral_index.bat inputRasterFilename spectralIndex outputRasterFilename

   echo.

   echo Example:

   echo.

   echo example_spectral_index.bat "c:/input.dat" "Normalized Difference Vegetation Index" "c:/output.dat"

   echo.

 

   exit /B 1

 

:START

   if [%1]==[] GOTO USAGE

   if [%2]==[] GOTO USAGE

   if [%3]==[] GOTO USAGE

 

::----------------

:: Input Arguments

::----------------

 

:: Input arguments are strings

   set "input_file=%1"

   set "spectral_index=%2"

   set "output_raster_uri=%3"

 

:: Remove double quotes from the arguments, if any

   set input_file=%input_file:"=%

   set spectral_index=%spectral_index:"=%

   set output_raster_uri=%output_raster_uri:"=%

 

:: Now put double quotes around each input argument

   set input_file=^"%input_file%^"

   set spectral_index=^"%spectral_index%^"

   set output_raster_uri=^"%output_raster_uri%^"

 

::---------------------------------------------

:: Build input JSON describing the task to run.

::---------------------------------------------

 

   set json={

   set json=%json%    "taskName"    :    "SpectralIndex"

   set json=%json%  ,"inputParameters" : {

   set json=%json%        "input_raster":

   set json=%json%          {"url" : %input_file%, "factory":"URLRaster"}

   set json=%json%       ,"index" : %spectral_index%

   set json=%json%     ,"output_raster_uri": %output_raster_uri%

   set json=%json%     }

   set json=%json%}

 

::------------------------------------------------

:: Get the location of the envitaskengine relative to

:: the location of this script.

::------------------------------------------------

   set mypath=%~dp0

   ::now go up to levels

   pushd %mypath%

   cd ../..

   set loc=%CD%

   popd

 

::--------------------------------------------

:: Run the task.

:: Task output JSON will be written to stdout.

::--------------------------------------------

   echo %json% | "%loc%/bin/bin.x86_64/envitaskengine"