Running external programs

EasyMorph can run external applications and Windows shell commands either once or multiple times in a loop. Most frequently this is used for file manipulations (copying, renaming, unzipping, etc.) or integration with 3rd party applications.

Running external program

The "Run program" transformation starts specified external application with command-line arguments (if required), and waits until it finishes.

The command line arguments for the application can be specified either as a constant line of text, or using an expression. In the latter case, the expression can use project parameters (but not field names).

Hint: Wrap file names in double quotes in command line expressions as they may contain spaces.

Executing Windows shell command

If application is not specified (the application path is empty) then "Run program" executes the command line as a Windows shell command. The example below shows using "Run program" for copying a file.

A common use case for "Run program" is reusable projects for file operations. In the example above the old file location and the new location are specified by parameters. Now, if we save this project as, say, file_copy.morph we obtain a reusable generic project that can be called from other projects whenever we need to copy a file. All that the calling project has to do is provide old and new locations for each file that has to be copied. Typically reusable projects are used in iterations.

Following this example you can have a library of reusable projects for various file operations like deleting, moving or renaming files. Typical use cases for mass operations with files include:

  • Copying or deleting files in a list
  • Moving files from a folder to different destination folders based on file name, size or extension
  • Renaming files using complex rules that can include, for instance, retrieving a date from a file's content and then using it for a new name of the file
  • File encoding/decoding

Advanced topics

Iterating external program or Windows shell command

Similarly to iterating EasyMorph projects, external applications can be iterated as well with the help of the "Iterate program" transformation. This transformation is similar to "Iterate" transformation, but instead of running another EasyMorph project it runs specified external application once for each row of a dataset. The command line in this case is specified using an expression. Therefore it can be calculated for each line of the dataset using fields, functions and parameters.

If the external application is not defined, the transformation executes the command line as a Windows shell command. It can be used, for instance, for mass copying/deleting/moving files without reusable projects.

Hint: To see what a calculated command line would look like you can pre-calculate command lines as a new column before iterating.

Capturing output

The "Run program" transformation allows capturing terminal screen output of an application or Windows shell commands. To capture output tick "Capture output" checkbox in the transformation properties. Both STDOUT and STDERR are captured. Typical use cases for output capturing include error handling and obtaining calculation results from extrnal applications without creating a file.

Read next: Data analysis