Reputation: 415
I'm trying to call a perl script using powershell as follows:
$plScript = Join-path $pwd 'Tools\myScript.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
This fails with the following message:
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
Using Trace-Command, I see where it fails, but can't understand what's wrong
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()
What am I missing ?
Running this in powershell v3 succeeds with no errors... but I must support v2 for this assignment...
Upvotes: 1
Views: 2539
Reputation: 202072
Seems like the perl process is exiting before the command can get the process's id. Try it this way to see if you can get past this - perhaps figure out why perl is exiting early:
$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)"
}
Upvotes: 2