1

I am trying to run a Informatica PowerCenter workflow using pmcmd command from Strawberry Perl. I am failing the working in case of any errored data received in the source files. Once PowerCenter workflow fails, I want to send an email from Perl script (not from Post session task in Session properties). Please help in capturing the workflow status from perl script. I really appreciate your time and help.

I tried multiple options like using system(), qw(), IPC::Run3 , IPC::System::Simple qw(system) etc but still I am not able to capture the success or failure of the workflow execution. I am aware of the pmcmd getworkflowdetails as well but that would be my last option.

use strict;
use warnings;
use IPC::Run3;

use IPC::System::Simple qw(system);
my ($stdout, $stderr,$command,$run);

$command = "pmcmd.exe startworkflow -sv......." # not putting the complete command as it is very lengthy
$run = run3($command);

if ( $run == 0) {
print "success";
} else {
print "fail ";
}

I have 2 workflows, 1 fails and 1 run successful. But whichever option I have tried, it gives same result for both the workflow execution.

2 Answers2

2

These methods each have different ways of indicating success, and there are also two different kinds of success: whether it successfully executes, and the exit status returned by the process.

IPC::System::Simple system will throw an exception if the command fails or returns a non-zero status. You can define acceptable non-zero statuses by passing an arrayref as the first argument. It is easiest when you want to allow errors to cause your program to die with a useful error message, so you don't need any exception handling like eval or try/catch.

use strict;
use warnings;
use IPC::System::Simple qw(system EXIT_ANY);

system $cmd; # failure or non-zero exit will cause program to die

my $exit = system EXIT_ANY, $cmd; # failure to execute will cause program to die

use Syntax::Keyword::Try;
try {
  system $cmd;
} catch {
  # error in $@
}

try {
  my $exit = system [0..5], $cmd;
  if ($exit) {
    # one of the allowed non-zero exit status
  }
} catch {
  # error in $@
}

try {
  my $exit = system EXIT_ANY, $cmd;
  if ($exit) {
    # non-zero exit status
  }
} catch {
  # error starting command in $@
}

IPC::Run3 will throw an exception if the command fails, and set $? to the wait status. Its return value is always true.

use strict;
use warnings;
use IPC::Run3;
use Syntax::Keyword::Try;

try {
  run3 $cmd;
  if ($?) {
    # non-zero exit status
    my $exit = $? >> 8;
  }
} catch {
  # error starting command in $@
}

qx or backticks which is the readpipe operator will not throw an exception, but will return undef if the command failed to start, and otherwise set $? the same way as IPC::Run3.

use strict;
use warnings;

my $output = `$cmd`;
if (!defined $output) {
  # error occured starting command, check $!
} elsif ($?) {
  # non-zero exit status
  my $exit = $? >> 8;
}

The built-in system function will return the wait status, or -1 if the command failed to start, and set the same value in $?.

use strict;
use warnings;

system $cmd;
if ($? == -1) {
  # error occured starting command, check $!
} elsif ($?) {
  # non-zero exit status
  my $exit = $? >> 8;
}

Note that all of these options aside from the readpipe operator (but see my IPC::ReadpipeX) support passing a command in list form, which bypasses the shell and thus safer when the command may contain arbitrary input, but sometimes can be buggy on Windows as it only pretends to bypass the shell there.

system 'pmcmd.exe', 'startworkflow', '-sv', ...;
run3 ['pmcmd.exe', ...];
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Grinnz
  • 9,093
  • 11
  • 18
1

Thank you Grinnz for your time and explanation ! It really helped for my knowledge. For my question, issue was with my pmcmd command. I was missing -wait option to use as an argument. Hence, pmcmd command was just returning a generic error code which was 0. After using -wait, I could capture the workflow failure status. Thanks once again !

For anyone out there facing same issue, here is the complete command I am using :

pmcmd.exe startworkflow -sv <integrationservice> -d <domain> -u <user> -p <pwd> -f <folder name> -paramfile <parameter file name> -wait <workflow name>