Skip to content

Instantly share code, notes, and snippets.

@WilliamBerryiii
Last active August 29, 2015 14:19
Show Gist options
  • Save WilliamBerryiii/ffe6975c1a092f39dd1a to your computer and use it in GitHub Desktop.
Save WilliamBerryiii/ffe6975c1a092f39dd1a to your computer and use it in GitHub Desktop.
Get IronPython Version from path ipy in Powershell
function Get-IpyVersionFromPath
{
.{
$version = ''
$ipyPath = Get-Command ipy | Select-Object -ExpandProperty Definition
if( [string]::IsNullOrEmpty($ipyPath) ) { return "IPY not in path" }
$ipyFolder = split-path $ipyPath
$ipyDll = join-path $ipyFolder 'IronPython.dll'
[reflection.assembly]::LoadFrom($ipyDll)
$py = [ironpython.hosting.python]::CreateEngine()
$pyv = $py.CreateScope()
$pyc = $py.CreateScriptSourceFromString("import sys; d = sys.version")
$pyc.Execute($pyv)
$d = ($pyv.GetVariable("d") -split ' ')
$version = $d[0]
} | Out-Null
$version
}
Write-host (Get-IpyVersionFromPath)
@WilliamBerryiii
Copy link
Author

Could also use the following if you don't need to interact with IronPython:
(ipy -c "import sys; print sys.version") | Out-String

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment