私は以下のようにpowershellを使ってperlスクリプトを呼び出そうとしています:
$plScript = Join-path $pwd "ToolsmyScript.pl"
$plOut = New-Item out.txt -type file -force
$plArgs = @($plScript, "--files","*.c", "AddInc=Tools","Addlib=Tools")
Start-Process perl.exe -ArgumentList $plArgs -RedirectStandardOutput $plOut - wait
これは、次のメッセージで失敗します。
Start-Process : Process with an Id of 80096 is not running.
+ Start-Process <<<< perl.exe -ArgumentList $plArgs -RedirectStandardOutput $plOut -wait
+ CategoryInfo : NotSpecified: (:) [Start-Process], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.StartProcessCommand
Trace-Commandを使用すると、どこが失敗するのか分かりますが、何が間違っているのか理解できません
DEBUG: ParameterBinding Information: 0 : CALLING BeginProcessing
DEBUG: ParameterBinding Information: 0 : System.ArgumentException: Process with an Id of 150588 is not running.
at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
at Microsoft.PowerShell.Commands.StartProcessCommand.start(ProcessStartInfo startInfo)
at Microsoft.PowerShell.Commands.StartProcessCommand.BeginProcessing()
at System.Management.Automation.Cmdlet.DoBeginProcessing()
at System.Management.Automation.CommandProcessorBase.DoBegin()
私は何が欠けていますか?
PowerShell v3でこれを実行するとエラーは発生しませんが、この割り当てではv2をサポートする必要があります...
回答:
回答№1は2コマンドがプロセスのIDを取得できるようになる前に、perlプロセスが終了しているように見えます。これを試してみてください。おそらく、なぜperlが早期に終了しているのか、
$p = Start-Process perl.exe -ArgumentList $plArgs -RedirectStandardOutput $plOut -PassThru
if (!$p.HasExited) {
$p.WaitForExit()
}
else {
"Hmm why did the process exit so early, exit code was: $($p.ExitCode)"
}