APGen Documentation Previous Topic: Executing APG Scripts within Windows Explorer Next Topic: Scheduled Execution of APG Scripts Parent Topic: Executing APG Scripts    Executing APG Scripts
Executing APG Scripts from the Command Line
See Also:

APG scripts can be run from the command line using the following syntax:

[APGen] script_path [param list] [/?] [/n | /s | /m] [/d | /nd | /b]

Term Description
APGen Path of APGen.exe or APGenCmd.exe. This term is optional when script_path has the .APG extension.
script_path Path of an APG script.
param list List of script parameters.  Parameters are delimited by spaces.  If a parameter contains a space, then the parameter must be surrounded by quotes.  These parameters will appear as strings in the Script.Arguments collection.
/? Show APGen.exe or APGenCmd.exe usage.
/n No status dialog.
/s Show status dialog.
/m Show status dialog minimized.
/d Enable script debugging.
/nd Disable script debugging.
/b Break at beginning of script in the debugger.

The [APGen] term does not have to be included before script_path if the script has the ".apg" extension - registry settings specify that all files with the ".apg" extension are executed by APGen.exe.  Similarly, if an APG script does not have the ".apg" extension, then the [ APGen] term must be included.

If the [APGen] term is included, then either APGen.exe (or APGenCmd.exe) must be in the current PATH, or the full path of APGen.exe (or APGenCmd.exe) must be used.  This full path will look something like:

"c:\program files\apgen\bin\APGen.exe"

The command line switches /n, /s, and /m are implemented by setting different values for the APGen.StatusDlg property.

Command line switch /d sets APGScript.Debug to True.  Command line switch /nd sets APGScript.Debug to False.  Command line switch /b sets APGScript.Debug to True, and APGScript.StartInDebugger to True.

Example:

This example runs an APG script from the command line:

C:\temp> test.apg param1 param2 "parameter 3" /s

This example passes 3 parameters to the script, and displays a status dialog while the script is running.

APGen.exe vs. APGenCmd.exe

APGen ships with two programs for running APG scripts: APGen.exe and APGenCmd.exe.  Both programs use the same command line switches, and provide the same script execution behavior.  These programs are used to execute APG scripts within Windows Explorer and from the Command Line.  Neither program is used for programmatic execution - programmatic execution uses the APGen COM object, which runs in the host's process.

The difference between the two programs is that APGen.exe is a Windows program, and APGenCmd.exe is a Windows console program.  When run from a Command Prompt, APGen.exe starts a new process and returns immediately, while APGenCmd.exe runs the APG script in the console, and does not return until the script has been executed.

APGenCmd.exe provides better behavior when running APG scripts in batch files, for two reasons:

  1. Script execution is synchronous - the batch file does not continue execution until the APG script has completed.
  2. The errorlevel value can be examined to determine if the APG script raised an error.

By default, APGen.exe is used to execute APG scripts on the command line and in Windows Explorer.  APGen.exe is preferred for executing APG scripts in Windows Explorer, since it is a Windows program.  APGenCmd.exe is the preferred executable when running APG scripts in a batch file, since it offers better behavior for batch files.

This batch file (run_apg.bat) executes an APG script, examines the errorlevel variable, and reports whether execution was successful:

echo off
echo ***********************************************
echo *  Running test APG script                    *
echo ***********************************************


REM Save the current search path
Set SavePath=%Path%

REM Set the path to include the APGen\bin dir
Path "C:\Program Files\APGen\Bin";%PATH%


REM Run test.apg - no debugging
APGenCmd.exe ".\apg\test.apg" /s /nd


REM Test for success. Quit if there was a compiler error.
If errorlevel 1 goto ScriptErrorOccurred
  
REM If we're here, the script was successfully run
   Echo *** APG script successfully executed. ***
   Goto Done


    
REM Report the compiler error; then exit
:ScriptErrorOccurred
   Echo *** Error %errorlevel% occurred while running APG script. ***
   Goto Done

:Done
   REM Restore the search path
   Path=%SavePath%
   Set SavePath=