2

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?

2 Answers 2

2

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"
Sign up to request clarification or add additional context in comments.

1 Comment

$env:path = $env:path + "C:\test\ruby" this will enable you to use it in the same session, but it will not persist in other sessions so you will have to use the method in the answer to make it persist
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.