Last active
August 29, 2015 14:19
-
-
Save WilliamBerryiii/ffe6975c1a092f39dd1a to your computer and use it in GitHub Desktop.
Get IronPython Version from path ipy in Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could also use the following if you don't need to interact with IronPython:
(ipy -c "import sys; print sys.version") | Out-String