2016-10-06 109 views
0

我有以下PowerShell代码执行perl脚本:如何从Windows PowerShell脚本

$HOME_DIR=[Environment]::GetEnvironmentVariable("HOME") 
$WORKING_PATH="C:\tests\automation" 
$TOOLS_PATH="$WORKING_PATH\Tools" 

Start-Process -FilePath "$HOME_DIR\perl\perl.bat" "$TOOLS_PATH\my_perl_script.pl" -ArgumentList 'arg1' 'arg2' -NoNewWindow 

我收到提示:

Start-Process : A positional parameter cannot be found that accepts argument 'C:\tests\automation\Tools\my_perl_script.pl'. 
At C:\RunUIAutomaionTests.ps1:46 char:14 
+ Start-Process <<<< -FilePath "$HOME_DIR\perl\perl.bat" "$TOOLS_PATH\my_perl_script.pl" 
-ArgumentList 'arg1' 'arg2' -NoNewWindow 
&emsp;&emsp;+ CategoryInfo   : InvalidArgument: (:) [Start-Process], ParameterBindingException 
&emsp;&emsp;+ FullyQualifiedErrorId :<br>&emsp;&emsp;PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand 

我失去了我应该如何执行my_perl_script.pl使用perl.bat与参数'arg1''arg2'

+2

文件路径不能由两条路径组成:-)将你的pl路径移动到参数中。 – wOxxOm

回答

0

为什么这么复杂? 您可以doirectly调用Perl这样的: ...

$TOOLS_PATH="$WORKING_PATH\Tools" ...

的perl $ TOOLS_PATH \ my_perl_script.pl ARG1 ARG2

只要确保Perl可执行文件是Windows路径