Ansys provides the /sys and /syp commands (they've been disabled in AnsysED 5.7 and later) as a means of running external programs. In order to run Perl scripts, Ansys must know which directories the Perl interpreter and the script are in.
In the UNIX/Linux environments, this is no problem. The /sys and /syp commands only need be provided with the full path to the script or just its name if it resides in a directory included in the PATH variable. The script is run using the system shell which looks at the first line in the script to see what interpreter should be used to execute the script.
Ansys on the Windows platform runs commands through the an archaic DOS shell which does not know enough to look at the first line of the script. A work around for this is typically achieved by requiring that all Perl scripts have a .pl extension and defining it as a registered file type in Windows Explorer. As a registered filetype, a run or open action is assigned with the full path name of the Perl interpreter. See The Hard Way to Run Perl Scripts From Ansys on Windows for more details on this approach.
The above approach of registering file types is very tricky for windows
users to setup. They usually have never done it before and find
the preocees very confusing and complicated. Additionally,
everything has to be set exactly right or it won't work and it won't be
clear why it failed. A greatly improved and recommended method
of running the the Perl scripts from Ansys on the Microsoft Windows
platform is to call it from within a DOS batch file.
The DOS Batch File
The following batch file, runperl.bat:
@echo off
set INTERP=e:\cygwin\bin\perl
set SCRIPT=e:\cygwin\usr\local\bin
%INTERP% %SCRIPT%\%1 %2 %3 %4 %5 %6 %7 %8 %9
is a generic batch for for running perl scripts. The environment variable INTERP gives the full path name of the perl interpreter. In this example it is set to the perl executable that comes with Cygwin, http://sources.redhat.com/cygwin. The SCRIPT variable provides the path to where the Perl scripts are located. It assumes all scripts are stored in the same directory. Alternatively, you could setup a batch file for each Perl script and call out the full path name within the batch file. These variables should set specifically for each machine.
This batch file should be placed in a directory that is in the PATH environment variable.
Running Perl Scripts From an Ansys Macro Via the Batch File
Perl commands can then be run from the input line or within an Ansys
Parametric Design Language (APDL) macro as shown in the following:
name='Fred'
/syp,runperl hello.pl,name
or
/sys,runperl hello.pl Fred
This approach has the additional advantage of being very easy to debug. Simply run runperl from a DOS shell and get it working before trying it in Ansys. Don't use commas when running it from the DOS prompt:
runperl hello.pl Fred
If you download runperl.tgz, extract it with WinZip and run the above command within a DOS shell (Command Prompt) you should see the following output:
Hello Fred!