如何从Windows PowerShell脚本
问题描述:
我有以下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
  + CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
  + FullyQualifiedErrorId :<br>  PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand
我失去了我应该如何执行my_perl_script.pl
使用perl.bat
与参数'arg1'
和'arg2'
?
答
为什么这么复杂? 您可以doirectly调用Perl这样的: ...
$TOOLS_PATH="$WORKING_PATH\Tools" ...
的perl $ TOOLS_PATH \ my_perl_script.pl ARG1 ARG2
只要确保Perl可执行文件是Windows路径
文件路径不能由两条路径组成:-)将你的pl路径移动到参数中。 – wOxxOm