{{ transformations:IterateProgramAction.png}}
====== ITERATE PROGRAM ======
Category: Workflow / External\\

\\ 
=====Description=====
This action runs the specified external application once for every line in the table.

The action fails if the extеrnal application returns a non-zero exit code.

\\
=====Use cases=====
  * Run external applications (e.g. after a file is generated by EasyMorph) against a list of parameters generated in EasyMorph.
  * Execute Windows shell commands (copy, del, ren, etc.) for a list of files generated in EasyMorph (e.g. using [[transformations:filelist|List of files]] action).
  * Run another EasyMorph project in order to generate different reports for each line of the table (e.g. one report per country).
\\ 
=====Action settings=====
^ Setting  ^ Description  ^
|Application<sup>*</sup>|Enter or browse to the fully qualified path and filename of the program's executable file.  If this is left blank,\\ the command line is executed by the Windows shell (cmd.exe).|
|Working directory (optional)<sup>*</sup>|Enter the folder containing any files required by the application.|  
|Arguments|Enter the values, filenames, commands, etc. passed to the application as a calculated expression.|
|Halt if exit code is not 0|When this is checked, the workflow will stop and display an error if the program terminates with an error.|
<sup>*</sup> Setting can be specified using a [[:parameters|parameter]].\\

\\ 
=====Remarks=====

====Parameter substitution====
The action uses a calculated expression to create its command line. It is possible to insert [[:parameters]] as well as column names into the expression.

	“copy /Y “ & {SourceFolder} & [Filename] & “ “ & {DestinationFolder} & [Filename]

Note that //SourceFolder// and //DestinationFolder// are parameter names, while [Filename] is a table column.

\\
=====Examples=====
**Example:**  Batch-delete files using the Windows "del" shell command.  The fully qualified filenames are stored in the "File name with full path" column in the dataset.

**Action parameters:**
> Application is left blank (command will run as a Windows shell command)
> Working directory is left blank (no folder assignment is necessary for this command)
> Calculated argument '' 'del /q "' & [File name with full path] & '"' ''
> Halt if exit code is not 0 is checked (the workflow will stop with an error the "del" command does not complete correctly)

{{  https://easymorph.com/images/learn/iterate-program.png  }}

\\ 
=====See also=====

  * [[transformations:callpython|Call Python]]
  * [[transformations:runprogram|Run program]]
  * [[https://easymorph.com/learn/external-programs.html|Tutorial:Executing external programs]]
