Call ruby script from powershell

后端 未结 1 1122
甜味超标
甜味超标 2021-01-14 04:51

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

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


        
1条回答
  •  难免孤独
    2021-01-14 05:22

    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.

    0 讨论(0)
提交回复
热议问题