Mayank Srivastava
Mayank Srivastava

Reputation: 159

Powershell Script to run Python Script

I need to run a python script on windows environment using powershell as an option only as my Bamboo Env will invoke that only.

I need powershell script which will call python script and should fail if python return status as 1. I'm not able to do so, can you please help me here.

Upvotes: 1

Views: 3693

Answers (1)

JosefZ
JosefZ

Reputation: 30113

Check $LASTEXITCODE automatic variable.

$LASTEXITCODE

Contains the exit code of the last Windows-based program that was run.

A sample Powershell script (apply . Dot sourcing operator to run a python script):

. py SomePythonScript.py
if ( $LASTEXITCODE -ne 0 ) { 
   Write-Warning "Exiting with code $LASTEXITCODE" 
   exit $LASTEXITCODE
}
### sample Powershell script continues here on `$LASTEXITCODE -eq 0` condition

Upvotes: 2

Related Questions