-4

I am trying to create a file .ps1 and writing the content using ruby.But i'm getting error.Below is the code

output = File.open( "test.ps1", "w" )
  output << "$a = type c://edmundsapi-final ;(Get-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config) -replace '(?<=<add key="Edmunds" value=")[^"]*', $a | Set-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config "
 output.close
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
charan k
  • 11
  • 1

1 Answers1

0

The syntax is either:

File.open("test.ps1", w) {|f| f.write("$a = type c://edmundsapi-final ;(Get-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config) -replace '(?<=<add key="Edmunds" value=")[^"]*', $a | Set-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config ") } 

or

out_file = File.new("test.ps1", "w") 
out_file.puts("$a = type c://edmundsapi-final ;(Get-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config) -replace '(?<=<add key="Edmunds" value=")[^"]*', $a | Set-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config ")

out_file.close

See "How to create a file in Ruby" for a possible duplicate.

Community
  • 1
  • 1
innuendomaximus
  • 353
  • 2
  • 3
  • 17