KBEC-00013 - Invoking the same program, like Perl, on different platforms

Article ID:360033195191
2 minute readKnowledge base

Description

This article explains how you can call the same program on different platforms, using different names, paths, and parameters for the program.

If you work in a multi-platform environment, especially if some platforms are UNIX-based and others are Windows-based, the installation of tools and other programs probably differ across the platforms. If you have ElectricCommander steps you would like to run on either platform type, use this solution for those steps.

Also, you may have an environment where the machines are the same platform, but there is no installation consistency across those machines. For example, each developer’s machine may have its own, non-standard configuration for tool installations. This solution can be applied to this case as well.

Solution

The approach for this solution is to store a property on each ElectricCommander resource that defines the full path and name of the tool, as it exists on that particular resource. When the step runs, it uses a property reference to refer to the tool. Because the resource name is known, and the path is retrieved from the actual resource, the property will always resolve to the correct value.

Example

The following example is based on calling Perl, but it can work for "make", "cc", or anything else that runs on multiple platforms.

Create ElectricCommander resources for Windows and Linux

Create resources named "windows-1" and "linux-1", or use your existing resources. Either way, they must be created first, before adding the property.

Add a property to each ElectricCommander resource

Example for "windows-1". In this example, you must use "double quotes" or Windows will not parse the command when it runs.

name:  InvokePerlvalue: "c:\Program Files\FavoritePerl\perl"  (your perl interpreter goes here)

Example for "linux-1".

name:  InvokePerlvalue: /usr/bin/perl                         (your perl interpreter goes here)

Create a procedure to call the multi-platform tool

Give the procedure a parameter named "resourceForSteps". This parameter will be passed to the procedure to allow it to run the step on different resources running on different platforms.

Create a step in the procedure

Step name:

CallPerl

Command:

$[/myResource/InvokePerl] test.pl

Resource:

$[resourceForSteps]

Run the procedure

Run the procedure twice. For one of the runs, set the parameter to "windows-1" and for the other run, set the parameter to "linux-1". Notice that each step runs the Perl interpreter based on its resource’s definition of the Perl location.