我有一段代码需要在linux / unix版本以及windows上运行。我已经让它适用于linux / unix,但是Windows让我很难过。
在Linux / Unix上正常运行的代码段
sub startAgent
{
my $sth = $dbh->prepare( "SELECT ACTIVATION_KEY from AVSYS.agent_view WHERE HOST_NAME='$host'" ) or die "Can't prepare SQL statement: $DBI::errstr\n";
### Execute the statement in the database
$sth->execute
or die "Can't execute SQL statement: $DBI::errstr\n";
logger ("Fetch Activation Key: Pass\n");
### Retrieve the returned rows of data
my @row;
while ( @row = $sth->fetchrow_array( ) ) {
`echo $row[0]| $agent_dir/bin/agentctl start -k`;
}
if($? == 0)
{
logger ("Activate Agent with Activation key: Pass \n");
logger ("***AV Agent Installed Successfully!***\n");
}
else
{
logger ("Error occurred while activating agent\n");
exit 110;
}
}
在Windows上无效的代码段
sub startAgent_win
{
my $sth = $dbh->prepare( "SELECT ACTIVATION_KEY from AVSYS.agent_view W HERE HOST_NAME='$host'" )
or die "Can't prepare SQL statement: $DBI::errstr\n";
### Execute the statement in the database
$sth->execute
or die "Can't execute SQL statement: $DBI::errstr\n";
logger ("Fetch Activation Key: Pass\n");
### Retrieve the returned rows of data
my @row;
my $key_file = "tmp_agent_key.txt";
while ( @row = $sth->fetchrow_array( ) ) {
open(OF, "> $key_file") or emdcommon::EMD_PERL_ERROR("cannot ope n < $key_file: $!\n");
chomp $row[0];
print OF $row[0];
close (OF);
`$agent_dir/bin/agentctl.bat start -k < $key_file`;
}
if($? == 0)
{
logger ("Activate Agent with Activation key: Pass \n");
logger ("***AV Agent Installed Successfully!***\n");
unlink $key_file;
}
else
{
logger ("Error occurred while activating agent\n");
unlink $key_file;
exit 110;
}
}
我正在尝试运行一个以交互方式请求输入的命令:
agentctl start -k
Enter Activation Key:
<key will not be displayed as you type it>
然后失败并出现错误:
Enter Activation Key:
Activation Key Required.
The agent must be started with an Activation Key.
在尝试手动重现该问题时,我发现只有当我没有指定“-k”时才会出现上述错误,而不是在我运行完整命令并且不提供激活密钥时出现。
即。如果我运行“agentctl start”,那么我会收到错误
需要激活密钥。 必须使用激活密钥启动代理。
但如果我运行“agentctl start -k”,那么我会收到错误
必须使用激活密钥启动代理。
我的猜测是在Windows上“ - ”在“-k”中被误解并导致问题。我尝试了很多不同的选择,没有任何成功。
如果你能帮我解决这个问题,我真的很感激。我是否必须使用其他实用程序来运行Windows命令?
感谢您调查此问题。 -Hozy