5

i have following situation: a powershell script with this variables:

$RUBY = "C:\installing\ruby\bin\ruby.exe"
$ARGS = "C:\files\sript.rb $Arg1 $Arg2 $Arg3"

in a batch file i can write

%RUBY% %ARGS% 

and it works.

but how can i do this in powershell?

It is important that the ruby installing path is variable.

I tried it with Start-Process but only ruby.exe was started, without script.

Any hints?

Thanks.

1
  • Have you tried $RUBY $ARGS ? Commented Aug 8, 2012 at 20:26

1 Answer 1

4

First, $args is an automatic variable managed by PowerShell, so I would avoid trying to declare your own variable with the same name.

To invoke a command stored in a variable from PowerShell, you can use the call operator &:

& $ruby 'script.rb'

If you need to build up the list of arguments, I would recommend creating an array, instead of mashing them all together into a single string:

$rubyArgs = @('C:\files\script.rb', $Arg1, $Arg2, $Arg3)
& $ruby $rubyArgs

If you need to pass more complicated arguments, you may find this answer useful.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - this helped me with getting my ruby script, which ran fine while in a powershell window on a vm, to run correctly when executing in a jenkins job using the powershell plugin.

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.