Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
iwpt_compile
System
Hi,
I am still very new to perl. I am executing iwpt_compile via an external task in my workflow. I am executing a perl script which then executes iwpt_compile. Everything is working fine. But, I would like to check the return code from iwpt_compile, and if it is not good, discontinue workflow. Forgive me for my ignorance, can someone show me some sample code that checks the return code from iwpt_compile and then discontinues workflow.
I would appreciate it!
Thanks in Advance,
Annie
Find more posts tagged with
Comments
Migrateduser
Can you post the portion of the script that calls iwpt_compile.ipl?
Generally you can interpret any non-zero return code as an error in command line execution. In the case of iwpt_compile.ipl you may also wish to trap any output as error, since that usually represents some sort of condition in the data or presentation template that you would like to trap. If you are going to be making lots of calls to command lines (which is pretty common in TeamSite), consider writing a subroutine in a module that you can pass any command line and get the results. Maybe something like:
sub run( $ )
{
my ${cmd} = shift( @{_} );
my %{results} = ();
${results{'cmd'}} = ${cmd};
${results{'out'}} = `${cmd} 2>&1`;
${results{'ret'}} = $?;
${results{'err'}} = $!;
${results{'msg'}} = ${results{'cmd'}} . " returned ${results{'ret'}} (${results{'err'}}) :\n${results{'out'}}";
return( %{results} );
}
So you can run your command with something like:
my %{results} = run( "iwpt_compile.ipl ..." );
if ( ${results{'ret'}} != 0 || ${results{'out'}} =~ m#..# )
{
# do something such as callback error successorset or otherwise report ${results{'msg'}}
}
If you don't want to bother with a subroutine, just use backticks to execute the command (you probably want to redirect STDERR to STDOUT using the 2>&1) and check the results in $?.
my ${output} = `iwpt_compile.ipl ... 2>&1`;
if ( $? != 0 || ${output} =~ m#..# )
{
# something unexpected happened - callback with error successorset or otherwise report exception
}
Migrateduser
Here's a snippet of my code.
if( $command eq 'iwpt' )
{
my $dcr = $args[ 0 ] ;
my $pt = $args[ 1 ] ;
my $out = $args[ 2 ] ;
my $pt_compiler = "$iwhome/bin/iwpt_compile.ipl" ;
my $cmdline = "\"$pt_compiler\" -pt \"$area/$pt\" -iw_pt-dcr \"$area/$dcr\" -iw_include-location \"$area\" -ofile \"$area/$out\" -oenc UTF-8" ;
if( $debug ) { print "generating: $cmdline\n" ; }
my
@out
= `$cmdline` ;
}
Migrateduser
my
@out
= `$cmdline` ;
I would change that to
my
@out
= `$cmdline 2>&1` ;
Right after this line confirm that $? == 0, otherwise you probably have an error. I have never put the output in an array (
@out)
, only a scalar ($out) - I guess if you do that you could just check if there are items in the array (assuming you want to trap the case where the PT generates console output, which is usually an error or at least a warning condition).
Migrateduser
John,
Thanks so much for your suggestions. Everything is working fine now.
Annie