Reputation: 33059
I have the following in a PowerShell script:
cmd /c npm run build-release
$succeeded = $LastExitCode
What I'd like to do is:
cmd
to a variable so it doesn't write to the host$succeeded
is eq $true
, Write-Host
the output variable from that the cmd
How can this be done?
Upvotes: 0
Views: 845
Reputation: 22821
Use Invoke-Expression
:
$output = Invoke-Expression "cmd /c npm run build-release"
$succeeded = $LastExitCode
if($succeeded -eq 0) {
write-output $output
}
Upvotes: 1