如何使用 pmcmd 命令行在 PERL 环境中捕获 PowerCenter 工作流的 success/failure 状态?

How to capture the success/failure status of the PowerCenter workflow in PERL environment using pmcmd command line?

我正在尝试使用 Strawberry Perl 中的 pmcmd 命令 运行 Informatica PowerCenter 工作流。如果源文件中收到任何错误数据,我将无法正常工作。一旦 PowerCenter 工作流失败,我想从 Perl 脚本(而不是从会话属性中的 Post 会话任务)发送一封电子邮件。请帮助从 perl 脚本捕获工作流状态。非常感谢您的宝贵时间和帮助。

我尝试了多种选择,例如使用 system()、qw()、IPC::Run3、IPC::System::Simple qw(system) 等,但我仍然无法捕捉到工作流程的成功或失败执行。 我也知道 pmcmd getworkflowdetails 但那将是我最后的选择。

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 ";
}

我有 2 个工作流,1 个失败,1 个 运行 成功。但是无论我尝试过哪个选项,它都会为工作流执行提供相同的结果。

这些方法各自有不同的表示成功的方式,成功也有两种不同的类型:是否执行成功,以及进程退出状态return

如果命令失败或 return 为非零状态,

IPC::System::Simple system 将抛出异常。您可以通过将 arrayref 作为第一个参数传递来定义可接受的非零状态。当您希望允许错误导致您的程序因有用的错误消息而死时,这是最简单的,因此您不需要任何异常处理,如 eval 或 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 $?转为等待状态。它的 return 值始终为真。

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 $@
}

qxreadpipe 运算符的反引号不会抛出异常,但如果命令启动失败,则会 return undef,否则设置 $?与 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;
}

内置的system函数会return等待状态,如果命令启动失败则为-1,并在$?.[=24中设置相同的值=]

use strict;
use warnings;

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

请注意,除了 readpipe 运算符(但请参阅我的 IPC::ReadpipeX)之外,所有这些选项都支持以列表形式传递命令,这会绕过 shell,因此当命令可能包含时更安全任意输入,但有时在 Windows 上可能会出现错误,因为它只是假装绕过那里的 shell。

system 'pmcmd.exe', 'startworkflow', '-sv', ...;
run3 ['pmcmd.exe', ...];

感谢 Grinnz 的宝贵时间和解释!这真的有助于我的知识。对于我的问题,问题出在我的 pmcmd 命令上。我缺少用作参数的 -wait 选项。因此,pmcmd 命令只返回一个通用错误代码 0。使用 -wait 后,我​​可以捕获工作流失败状态。再次感谢 !

对于遇到同样问题的任何人,这是我正在使用的完整命令:

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