简体   繁体   English

如何从PERL将参数传递给Powershell并保留输出?

[英]How to pass argument to Powershell from PERL and retain the output?

I'm trying to pass an argument to a Powershell script via PERL and then retain the output for use later in the script. 我试图通过PERL将参数传递给Powershell脚本,然后保留输出以供稍后在脚本中使用。 I cannot seem to get it to work. 我似乎无法使其正常工作。

PERL 佩尔

$var= 1000;

my @output = `powershell.exe C:\\Workspace\\Utilities\\pathtoscript.ps1`.` $var`;
foreach (@output)
{
   print $_;
}

The powershell script appears to fail as if it's not receiving the argument. Powershell脚本似乎失败,就好像没有收到参数一样。 The powershell script is supposed to use that value and determine a new value based on the original value and pass it back to PERL to be used later in the PERL script. Powershell脚本应该使用该值并根据原始值确定新值,然后将其传递回PERL,以供稍后在PERL脚本中使用。

I have attached another example of what i tried, which also fails in the same 我已附上我尝试过的另一个示例,同样也失败了

Alternate Script 备用脚本

$center = 1000;
print "Getting business unit...\n";
my $renamecmd = 'Powershell.exe -executionpolicy remotesigned -File C:\Workspace\Utilities\get_business_unit.ps1'." $center";
my @output = `$renamecmd`;
foreach (@output)
{
   print $_;
}

Thanks in advance! 提前致谢!

I figured it out... I also wrapped it in a fuction 我想通了...我也把它包裹起来

sub getvalue{
print "Getting value...\n";
my $renamecmd = 'Powershell.exe -executionpolicy remotesigned -File C:\Workspace\Utilities\pathtofile.ps1'." $val";
my @output = `$renamecmd`;
foreach (@output) {
   print $_;
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM