Question

I have a binary executable called ruby.exe located in

C://test//ruby.exe

How can I make it as cmdlet using powershell script such that in my powershell script, i can run ruby directly?

Was it helpful?

Solution

You can add it to the PATH variable. Then directly call with with Ruby.exe:

$path = [Environment]::GetEnvironmentVariable("Path")
$path = $path + ";"C:\Test\Ruby"
[Environment]::SetEnvironmentVariable("Path", $path, [System.EnvironmentVariableTarget]::Machine )
$env:path = $env:path + "C:\test\ruby"

OTHER TIPS

I believe you're after "Splatting". The magic is in using the @ operator, which will pass a list of arguments (or a dictionary of arguments) to the underlying command. $psBoundParameters contains the magic data being passed down in splatting.

function Invoke-Ruby(
    [Parameter(ValueFromRemainingArgumnets=$True)][string[]]$Arguments
) { 
    c:\Test\Ruby.exe @Arguments
}

To read more about Splatting, check out this article on Hey, Scripting Guy

And, instead of trying to harness ruby in PowerShell, you might want to just try using PowerShell as a web framework (PowerShell Pipeworks)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top