Charlie Baum
Charlie Baum

Reputation: 107

Use Ruby variable when calling exec powershell.exe in script

Writing some ruby code, some of which will be making Powershell calls using the exec powershell.exe command.

How do I use an existing Ruby variable and pass it to the Powershell command?

Code:

mydata = 12345
exec 'Powershell.exe write-host #{mydata}'

That doesn't work. How do I use the mydata Ruby variable in the powershell call?

Upvotes: 0

Views: 863

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176342

In order to interpolate a value in a string, you need to use double quote.

exec "Powershell.exe write-host #{mydata}"

instead of

exec 'Powershell.exe write-host #{mydata}'

Upvotes: 2

Related Questions